You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4net-user@logging.apache.org by James Green <Ja...@occam-dm.com> on 2009/06/15 17:25:56 UTC

Using AdoNetAppender

Hi All,
 
I've spent about 4 hours today trying to get this working and have
totally failed so far.
 
I can't even really find much info on how to configure this purely in
Code.  In fact there is precious little I can find on the net in fact.
 
Here is the code I'm using the set up the AdoNetAppender in my app:
 
 
public static void ConfigureDatabaseAppender(string connString)
{
PatternLayout layout = GetDefaultLayout();
_sqlDatabaseAppender = new AdoNetAppender();
_sqlDatabaseAppender.Layout = layout;
_sqlDatabaseAppender.UseTransactions = false;
_sqlDatabaseAppender.BufferSize = 1;
 
_sqlDatabaseAppender.CommandType = System.Data.CommandType.Text;
_sqlDatabaseAppender.ConnectionString = connString;
_sqlDatabaseAppender.CommandText = "INSERT INTO Log
([Date],[Level],[Thread],[Logger],[Message],[Exception]) VALUES
(@log_date, @log_level, @thread, @logger, @message, @exception)";
AdoNetAppenderParameter logDate = new AdoNetAppenderParameter();
RawTimeStampLayout dateLayout = new RawTimeStampLayout();
logDate.ParameterName = "@log_date";
logDate.Layout = dateLayout;
logDate.DbType = System.Data.DbType.DateTime;
_sqlDatabaseAppender.AddParameter(logDate);
AdoNetAppenderParameter logThread = new AdoNetAppenderParameter();
logThread.ParameterName = "@thread";
logThread.Size = 255;
logThread.DbType = System.Data.DbType.String;
_sqlDatabaseAppender.AddParameter(logThread);
AdoNetAppenderParameter logLevel = new AdoNetAppenderParameter();
logLevel.ParameterName = "@log_level";
logLevel.Size = 50;
logLevel.DbType = System.Data.DbType.String;
_sqlDatabaseAppender.AddParameter(logLevel);
AdoNetAppenderParameter logLogger = new AdoNetAppenderParameter();
logLogger.ParameterName = "@logger";
logLogger.Size = 255;
logLogger.DbType = System.Data.DbType.String;
_sqlDatabaseAppender.AddParameter(logLogger);
AdoNetAppenderParameter logMessage = new AdoNetAppenderParameter();
logMessage.ParameterName = "@message";
logMessage.Size = 4000;
logMessage.DbType = System.Data.DbType.String;
_sqlDatabaseAppender.AddParameter(logMessage);
AdoNetAppenderParameter logException = new AdoNetAppenderParameter();
logException.ParameterName = "@exception";
logException.Size = 2000;
logException.DbType = System.Data.DbType.String;
_sqlDatabaseAppender.AddParameter(logException);
_sqlDatabaseAppender.ActivateOptions();
 
BasicConfigurator.Configure(_sqlDatabaseAppender);
}

Any help would be great.

James.


RE: Using AdoNetAppender

Posted by James Green <Ja...@occam-dm.com>.
Hi Ron,
 
I did actually spot this just after posting the code and it did remove
the connection error I was seeing.
 
However, we have got it logging the date values now, however the other
fields are @log_level etc ... are still null.
 
Any ideas?
 
Cheers,
 
James.

  _____  

From: Ron Grabowski [mailto:rongrabowski@yahoo.com] 
Sent: 15 June 2009 22:01
To: Log4NET User
Subject: Re: Using AdoNetAppender


If you don't specify a ConnectionType AdoNetAppender defaults to using
OleDbConnection which has a different connection string format than the
more common SqlConnection. Are you sure you want to use OleDbConnection?

Why not write a simple ConsoleApplication to test your code and look at
the configuration output log4net writes to Console.Out?

    class Program
    {
        private static AdoNetAppender _sqlDatabaseAppender = new
AdoNetAppender();

        static void Main(string[] args)
        {
            LogLog.InternalDebugging = true;
            LogLog.EmitInternalMessages = true;

            ConfigureDatabaseAppender("...");

            ILog log = LogManager.GetLogger(typeof(Program));
            log.Debug("Hello World");

            Console.ReadLine();
        }

        public static void ConfigureDatabaseAppender(string connString)
        {
        // snip



  _____  

From: James Green <Ja...@occam-dm.com>
To: Log4NET User <lo...@logging.apache.org>
Sent: Monday, June 15, 2009 12:04:16 PM
Subject: RE: Using AdoNetAppender


I think I'm going to have to try the config file method first.
 
I'm wrapping log4net and I don't want to cause every consuming component
to require loads of config information in it just for logging purposes.
 
Everything else is a sinch to configure in code, save for this appender
... *sigh* ...
 
Cheers,
 
James.

scanned by MessageLabs [www.messagelabs.com]


Re: Using AdoNetAppender

Posted by Ron Grabowski <ro...@yahoo.com>.
If you don't specify a ConnectionType AdoNetAppender defaults to using
OleDbConnection which has a different connection string format than the
more common SqlConnection. Are you sure you want to use OleDbConnection?

Why not write a simple ConsoleApplication to test your code and look at the configuration output log4net writes to Console.Out?

    class Program
    {
        private static AdoNetAppender _sqlDatabaseAppender = new AdoNetAppender();

        static void Main(string[] args)
        {
            LogLog.InternalDebugging = true;
            LogLog.EmitInternalMessages = true;

            ConfigureDatabaseAppender("...");

            ILog log = LogManager.GetLogger(typeof(Program));
            log.Debug("Hello World");

            Console.ReadLine();
        }

        public static void ConfigureDatabaseAppender(string connString)
        {
        // snip





________________________________
From: James Green <Ja...@occam-dm.com>
To: Log4NET User <lo...@logging.apache.org>
Sent: Monday, June 15, 2009 12:04:16 PM
Subject: RE: Using AdoNetAppender


I think I'm going to have to try the config file method 
first.
 
I'm wrapping log4net and I don't want to cause every 
consuming component to require loads of config information in it just for 
logging purposes.
 
Everything else is a sinch to configure in code, save for 
this appender ... *sigh* ...
 
Cheers,
 
James.

RE: Using AdoNetAppender

Posted by James Green <Ja...@occam-dm.com>.
> bet that was a 'punching hands in the air' geek moment from hell!!!!

Indeed ... I may even make a cup of tea to celebrate! :)

Cheers,

James.

Re: Using AdoNetAppender

Posted by Wayne Douglas <wa...@codingvista.com>.
bet that was a 'punching hands in the air' geek moment from hell!!!!

On Tue, Jun 16, 2009 at 10:58 AM, James Green<Ja...@occam-dm.com> wrote:
> Cracked it ...
>
>            AdoNetAppenderParameter logLevel = new
> AdoNetAppenderParameter();
>            logLevel.ParameterName = "@log_level";
>            logLevel.Layout = new Layout2RawLayoutAdapter(new
> PatternLayout("%level"));
>            logLevel.Size = 50;
>            logLevel.DbType = System.Data.DbType.String;
>            _sqlDatabaseAppender.AddParameter(logLevel);
>
> Regards,
>
> James.
>



-- 
Cheers,

w://

RE: Using AdoNetAppender

Posted by James Green <Ja...@occam-dm.com>.
Hi Again,

<snip>
</code>

Indeed, this isn't the most straight forward thing.

>and failed - but this is possibly because of a few things outside the
>responsibility of the log4net codebase.

>There's nothing wrong working through a poroblem - to help improve the
>situ - but just rubbishing it won't help anyone.

Sure, but when  your back is against the wall and you've been given a
day to write a complete logging library running up against this problem
when *everything* else works as expected is a bit frustrating.

What is even weirder is that I now have dates going into the database
... However, everything else is null ...

I've just pulled it down to two fields now, using this as a pattern:

"%date %level"

Date logs find ... Level is always null ...

You are right, rubbishing it is plain stupid on my part.

Cheers,

James.

Re: Using AdoNetAppender

Posted by Ron Grabowski <ro...@yahoo.com>.
You could have also copied the built-in TimeStamp layout

        // log4net.Layout
        public class RawTimeStampLayout : IRawLayout
        {
            public object Format(LoggingEvent loggingEvent)
            {
                return loggingEvent.TimeStamp;
            }
        }

and made your own Level layout:

        public class RawLevelLayout : IRawLayout
        {
            public object Format(LoggingEvent loggingEvent)
            {
                return loggingEvent.Level;
            }
        }



----- Original Message ----
From: James Green <Ja...@occam-dm.com>
To: Log4NET User <lo...@logging.apache.org>
Sent: Tuesday, June 16, 2009 5:58:12 AM
Subject: RE: Using AdoNetAppender

Cracked it ...

            AdoNetAppenderParameter logLevel = new
AdoNetAppenderParameter();
            logLevel.ParameterName = "@log_level";
            logLevel.Layout = new Layout2RawLayoutAdapter(new
PatternLayout("%level"));
            logLevel.Size = 50;
            logLevel.DbType = System.Data.DbType.String;
            _sqlDatabaseAppender.AddParameter(logLevel);

Regards,

James.


RE: Using AdoNetAppender

Posted by James Green <Ja...@occam-dm.com>.
Cracked it ...

            AdoNetAppenderParameter logLevel = new
AdoNetAppenderParameter();
            logLevel.ParameterName = "@log_level";
            logLevel.Layout = new Layout2RawLayoutAdapter(new
PatternLayout("%level"));
            logLevel.Size = 50;
            logLevel.DbType = System.Data.DbType.String;
            _sqlDatabaseAppender.AddParameter(logLevel);

Regards,

James.

Re: Using AdoNetAppender

Posted by Wayne Douglas <wa...@codingvista.com>.
No I haven't - and to be fair, I did try doing this a while ago:

<code file='global.asax' method='Application_Start'>

            log4net.Config.XmlConfigurator.Configure();

            //reset the logger to use the default con string - so we
only need to change it on one place
            var hier =
              log4net.LogManager.GetRepository() as
log4net.Repository.Hierarchy.Hierarchy;

            if (hier != null)
            {
                //get ADONetAppender
                var adoAppender =
(log4net.Appender.AdoNetAppender)hier.GetLogger("root",hier.LoggerFactory).GetAppender("AdoNetAppender");
                var adoAppender =
(log4net.Appender.AdoNetAppender)hier.Root.Appenders[0];
                if (adoAppender != null)
                {
                    adoAppender.ConnectionString =
AppSettings.GetConfigurationString("MainConnection");
                    adoAppender.ActivateOptions(); //refresh settings
of appender
                }
            }

</code>

and failed - but this is possibly because of a few things outside the
responsibility of the log4net codebase.

There's nothing wrong working through a poroblem - to help improve the
situ - but just rubbishing it won't help anyone.

w://

On Tue, Jun 16, 2009 at 10:08 AM, James Green <Ja...@occam-dm.com> wrote:
>
> Hi Wayne,
>
> I didn't wish to start a flame war.
>
> This is not the first time I've had trouble finding decent log4net docs when configuring without AppConfig, in fact Google hardly returns a thing on this topic.  Surely database logging is one of the most popular features and I'm highlighting what I think to be a massive gap in its documentation.
>
> I love log4net, it was a no brainer for me to pick but don't think getting this library configured using pure C# is easy.  Have you completed this task without using Xml config?  Xml config is not always possible nor desirable.
>
> James.
> ________________________________
> From: codingvista@googlemail.com [mailto:codingvista@googlemail.com] On Behalf Of Wayne Douglas
> Sent: 16 June 2009 09:58
> To: Log4NET User
> Subject: Re: Using AdoNetAppender
>
> why don't you write a fluent interface for it!?!?
>
> I think that for FREE software provided with SOURCE - it's a pretty darn good tool at a pretty darn good price - and so does the rest of the _whole_ industry - it being an _industry_ _standard_!
>
> There are plenty of other loggers out there too - for free - open source - some good some not so good - all off the backs of some very hard work by some very tallented and commited people.
>
> w://
>
> On Tue, Jun 16, 2009 at 9:48 AM, James Green <Ja...@occam-dm.com> wrote:
>>
>> Hi Again,
>>
>> Surely, this is all pointing to a far bigger problem.  That is an horrific piece of code!!  Surely this is doable in pure C#?
>>
>> I'm amazed that this AdoNetAppender is so poorly documented and has so few examples.  It's starting to put me off log4net!
>>
>> James.
>> ________________________________
>> From: Ron Grabowski [mailto:rongrabowski@yahoo.com]
>> Sent: 15 June 2009 22:32
>> To: Log4NET User
>> Subject: Re: Using AdoNetAppender
>>
>> This page shows an example of loading an xml string into an XmlDocument then configure log4net from the XmlDocument:
>>
>> http://svn.apache.org/viewvc/logging/log4net/trunk/tests/src/Appender/AdoNetAppenderTest.cs?view=co
>> ________________________________
>> From: James Green <Ja...@occam-dm.com>
>> To: Log4NET User <lo...@logging.apache.org>
>> Sent: Monday, June 15, 2009 12:04:16 PM
>> Subject: RE: Using AdoNetAppender
>>
>> I think I'm going to have to try the config file method first.
>>
>> I'm wrapping log4net and I don't want to cause every consuming component to require loads of config information in it just for logging purposes.
>>
>> Everything else is a sinch to configure in code, save for this appender ... *sigh* ...
>>
>> Cheers,
>>
>> James.
>> scanned by MessageLabs [www.messagelabs.com]
>
>
>
> --
> Cheers,
>
> w://
>
> scanned by MessageLabs [www.messagelabs.com]



--
Cheers,

w://

RE: Using AdoNetAppender

Posted by James Green <Ja...@occam-dm.com>.
Hi Wayne,
 
I didn't wish to start a flame war.
 
This is not the first time I've had trouble finding decent log4net docs
when configuring without AppConfig, in fact Google hardly returns a
thing on this topic.  Surely database logging is one of the most popular
features and I'm highlighting what I think to be a massive gap in its
documentation.
 
I love log4net, it was a no brainer for me to pick but don't think
getting this library configured using pure C# is easy.  Have you
completed this task without using Xml config?  Xml config is not always
possible nor desirable.
 
James.

  _____  

From: codingvista@googlemail.com [mailto:codingvista@googlemail.com] On
Behalf Of Wayne Douglas
Sent: 16 June 2009 09:58
To: Log4NET User
Subject: Re: Using AdoNetAppender


why don't you write a fluent interface for it!?!?

I think that for FREE software provided with SOURCE - it's a pretty darn
good tool at a pretty darn good price - and so does the rest of the
_whole_ industry - it being an _industry_ _standard_!

There are plenty of other loggers out there too - for free - open source
- some good some not so good - all off the backs of some very hard work
by some very tallented and commited people. 

w://


On Tue, Jun 16, 2009 at 9:48 AM, James Green <Ja...@occam-dm.com>
wrote:


	Hi Again,
	 
	Surely, this is all pointing to a far bigger problem.  That is
an horrific piece of code!!  Surely this is doable in pure C#?
	 
	I'm amazed that this AdoNetAppender is so poorly documented and
has so few examples.  It's starting to put me off log4net!
	 
	James.

  _____  

	From: Ron Grabowski [mailto:rongrabowski@yahoo.com] 
	Sent: 15 June 2009 22:32 

	To: Log4NET User
	Subject: Re: Using AdoNetAppender
	

	This page shows an example of loading an xml string into an
XmlDocument then configure log4net from the XmlDocument:
	
	
http://svn.apache.org/viewvc/logging/log4net/trunk/tests/src/Appender/Ad
oNetAppenderTest.cs?view=co

	
  _____  

	From: James Green <Ja...@occam-dm.com>
	To: Log4NET User <lo...@logging.apache.org>
	Sent: Monday, June 15, 2009 12:04:16 PM
	Subject: RE: Using AdoNetAppender
	
	
	I think I'm going to have to try the config file method first.
	 
	I'm wrapping log4net and I don't want to cause every consuming
component to require loads of config information in it just for logging
purposes.
	 
	Everything else is a sinch to configure in code, save for this
appender ... *sigh* ...
	 
	Cheers,
	 
	James.

	scanned by MessageLabs [www.messagelabs.com]
	




-- 
Cheers,

w://

scanned by MessageLabs [www.messagelabs.com]


Re: Using AdoNetAppender

Posted by Wayne Douglas <wa...@codingvista.com>.
why don't you write a fluent interface for it!?!?

I think that for FREE software provided with SOURCE - it's a pretty darn
good tool at a pretty darn good price - and so does the rest of the _whole_
industry - it being an _industry_ _standard_!

There are plenty of other loggers out there too - for free - open source -
some good some not so good - all off the backs of some very hard work by
some very tallented and commited people.

w://

On Tue, Jun 16, 2009 at 9:48 AM, James Green <Ja...@occam-dm.com>wrote:

>  Hi Again,
>
> Surely, this is all pointing to a far bigger problem.  That is an horrific
> piece of code!!  Surely this is doable in pure C#?
>
> I'm amazed that this AdoNetAppender is so poorly documented and has so few
> examples.  It's starting to put me off log4net!
>
> James.
>
>  ------------------------------
> *From:* Ron Grabowski [mailto:rongrabowski@yahoo.com]
> *Sent:* 15 June 2009 22:32
> *To:* Log4NET User
> *Subject:* Re: Using AdoNetAppender
>
>  This page shows an example of loading an xml string into an XmlDocument
> then configure log4net from the XmlDocument:
>
>
> http://svn.apache.org/viewvc/logging/log4net/trunk/tests/src/Appender/AdoNetAppenderTest.cs?view=co
>
>  ------------------------------
> *From:* James Green <Ja...@occam-dm.com>
> *To:* Log4NET User <lo...@logging.apache.org>
> *Sent:* Monday, June 15, 2009 12:04:16 PM
> *Subject:* RE: Using AdoNetAppender
>
> I think I'm going to have to try the config file method first.
>
> I'm wrapping log4net and I don't want to cause every consuming component to
> require loads of config information in it just for logging purposes.
>
> Everything else is a sinch to configure in code, save for this appender ...
> *sigh* ...
>
> Cheers,
>
> James.
>
> scanned by MessageLabs [www.messagelabs.com]
>



-- 
Cheers,

w://

RE: Using AdoNetAppender

Posted by James Green <Ja...@occam-dm.com>.
Hi Ron,
 
For sure, I totally understand that!
 
I think it would be good to include some C# config examples.  I just
have to finish off my wrapper and then I'll get my C# code over to you
for comment / inclusion in the docs.
 
Thanks!
 
James.

  _____  

From: Ron Grabowski [mailto:rongrabowski@yahoo.com] 
Sent: 16 June 2009 23:00
To: Log4NET User
Subject: Re: Using AdoNetAppender


Its quite difficult to document every possible usage of a library. In
addition to these documents:

http://logging.apache.org/log4net/release/config-examples.html
http://logging.apache.org/log4net/release/sdk/log4net.Appender.AdoNetApp
ender.html
http://logging.apache.org/log4net/release/sdk/log4net.Appender.AdoNetApp
enderParameter.Layout.html

There's about 8,000 search results on Google for AdoNetAppender. 

A lot of the documentation is focused on XML examples because that's how
the majority of the users configure log4net.

I'll glady add your code configuration examples to AdoNetAppenderTest.cs
if attach them to a JIRA ticket!


  _____  

From: James Green <Ja...@occam-dm.com>
To: Log4NET User <lo...@logging.apache.org>
Sent: Tuesday, June 16, 2009 4:48:27 AM
Subject: RE: Using AdoNetAppender


Hi Again,
 
Surely, this is all pointing to a far bigger problem.  That is an
horrific piece of code!!  Surely this is doable in pure C#?
 
I'm amazed that this AdoNetAppender is so poorly documented and has so
few examples.  It's starting to put me off log4net!
 
James.

  _____  

From: Ron Grabowski [mailto:rongrabowski@yahoo.com] 
Sent: 15 June 2009 22:32
To: Log4NET User
Subject: Re: Using AdoNetAppender


This page shows an example of loading an xml string into an XmlDocument
then configure log4net from the XmlDocument:

http://svn.apache.org/viewvc/logging/log4net/trunk/tests/src/Appender/Ad
oNetAppenderTest.cs?view=co

  _____  

From: James Green <Ja...@occam-dm.com>
To: Log4NET User <lo...@logging.apache.org>
Sent: Monday, June 15, 2009 12:04:16 PM
Subject: RE: Using AdoNetAppender


I think I'm going to have to try the config file method first.
 
I'm wrapping log4net and I don't want to cause every consuming component
to require loads of config information in it just for logging purposes.
 
Everything else is a sinch to configure in code, save for this appender
... *sigh* ...
 
Cheers,
 
James.

scanned by MessageLabs [www.messagelabs.com]


scanned by MessageLabs [www.messagelabs.com]


Re: Using AdoNetAppender

Posted by Ron Grabowski <ro...@yahoo.com>.
Its quite difficult to document every possible usage of a library. In addition to these documents:

http://logging.apache.org/log4net/release/config-examples.html
http://logging.apache.org/log4net/release/sdk/log4net.Appender.AdoNetAppender.html
http://logging.apache.org/log4net/release/sdk/log4net.Appender.AdoNetAppenderParameter.Layout.html

There's about 8,000 search results on Google for AdoNetAppender. 

A lot of the documentation is focused on XML examples because that's how the majority of the users configure log4net.

I'll glady add your code configuration examples to AdoNetAppenderTest.cs if attach them to a JIRA ticket!




________________________________
From: James Green <Ja...@occam-dm.com>
To: Log4NET User <lo...@logging.apache.org>
Sent: Tuesday, June 16, 2009 4:48:27 AM
Subject: RE: Using AdoNetAppender


Hi Again,
 
Surely, this is all pointing to a far bigger problem.  
That is an horrific piece of code!!  Surely this is doable in pure 
C#?
 
I'm amazed that this AdoNetAppender is so poorly 
documented and has so few examples.  It's starting to put me off 
log4net!
 
James.


________________________________
 From: Ron Grabowski 
[mailto:rongrabowski@yahoo.com] 
Sent: 15 June 2009 
22:32
To: Log4NET User
Subject: Re: Using 
AdoNetAppender


This page shows an example of loading an xml string into an XmlDocument 
then configure log4net from the XmlDocument:

http://svn.apache.org/viewvc/logging/log4net/trunk/tests/src/Appender/AdoNetAppenderTest.cs?view=co



________________________________
 From: James Green 
<Ja...@occam-dm.com>
To: Log4NET User 
<lo...@logging.apache.org>
Sent: Monday, June 15, 2009 12:04:16 
PM
Subject: RE: Using 
AdoNetAppender


I think I'm going to have to try the config file method 
first.
 
I'm wrapping log4net and I don't want to cause every 
consuming component to require loads of config information in it just for 
logging purposes.
 
Everything else is a sinch to configure in code, save for 
this appender ... *sigh* ...
 
Cheers,
 
James.
scanned by 
MessageLabs [www.messagelabs.com]

RE: Using AdoNetAppender

Posted by James Green <Ja...@occam-dm.com>.
Hi Again,
 
Surely, this is all pointing to a far bigger problem.  That is an
horrific piece of code!!  Surely this is doable in pure C#?
 
I'm amazed that this AdoNetAppender is so poorly documented and has so
few examples.  It's starting to put me off log4net!
 
James.

  _____  

From: Ron Grabowski [mailto:rongrabowski@yahoo.com] 
Sent: 15 June 2009 22:32
To: Log4NET User
Subject: Re: Using AdoNetAppender


This page shows an example of loading an xml string into an XmlDocument
then configure log4net from the XmlDocument:

http://svn.apache.org/viewvc/logging/log4net/trunk/tests/src/Appender/Ad
oNetAppenderTest.cs?view=co

  _____  

From: James Green <Ja...@occam-dm.com>
To: Log4NET User <lo...@logging.apache.org>
Sent: Monday, June 15, 2009 12:04:16 PM
Subject: RE: Using AdoNetAppender


I think I'm going to have to try the config file method first.
 
I'm wrapping log4net and I don't want to cause every consuming component
to require loads of config information in it just for logging purposes.
 
Everything else is a sinch to configure in code, save for this appender
... *sigh* ...
 
Cheers,
 
James.

scanned by MessageLabs [www.messagelabs.com]


Re: Using AdoNetAppender

Posted by Ron Grabowski <ro...@yahoo.com>.
This page shows an example of loading an xml string into an XmlDocument then configure log4net from the XmlDocument:

http://svn.apache.org/viewvc/logging/log4net/trunk/tests/src/Appender/AdoNetAppenderTest.cs?view=co



________________________________
From: James Green <Ja...@occam-dm.com>
To: Log4NET User <lo...@logging.apache.org>
Sent: Monday, June 15, 2009 12:04:16 PM
Subject: RE: Using AdoNetAppender


I think I'm going to have to try the config file method 
first.
 
I'm wrapping log4net and I don't want to cause every 
consuming component to require loads of config information in it just for 
logging purposes.
 
Everything else is a sinch to configure in code, save for 
this appender ... *sigh* ...
 
Cheers,
 
James.

RE: Using AdoNetAppender

Posted by James Green <Ja...@occam-dm.com>.
I think I'm going to have to try the config file method first.
 
I'm wrapping log4net and I don't want to cause every consuming component
to require loads of config information in it just for logging purposes.
 
Everything else is a sinch to configure in code, save for this appender
... *sigh* ...
 
Cheers,
 
James.

  _____  

From: codingvista@googlemail.com [mailto:codingvista@googlemail.com] On
Behalf Of Wayne Douglas
Sent: 15 June 2009 16:57
To: Log4NET User
Subject: Re: Using AdoNetAppender


AppConfig is much simpler - you should start with that then convert to
this if you need to - not sure why you'd need to tho?


On Mon, Jun 15, 2009 at 4:31 PM, James Green <Ja...@occam-dm.com>
wrote:


	I may have to try that.  Currently it just fails with an "Oject
	reference not set to an instance of an object."
	
	Thanks,
	
	James.
	

	-----Original Message-----
	From: Matt Lund [mailto:mlund@control4.com]
	Sent: 15 June 2009 16:28
	To: Log4NET User
	Subject: RE: Using AdoNetAppender
	
	Have you already gotten AdoNetAppender to work from a app.config
/
	web.config first?  If not, I'd suggest getting that to work
first.  You
	may learn something in that process and it'll spark a
realization of
	what you're missing in the from-code approach?
	
	-----Original Message-----
	From: James Green [mailto:James.Green@occam-dm.com]
	Sent: Monday, June 15, 2009 9:26 AM
	To: Log4NET User
	Subject: Using AdoNetAppender
	
	Hi All,
	
	I've spent about 4 hours today trying to get this working and
have
	totally failed so far.
	
	I can't even really find much info on how to configure this
purely in
	Code.  In fact there is precious little I can find on the net in
fact.
	
	Here is the code I'm using the set up the AdoNetAppender in my
app:
	
	
	public static void ConfigureDatabaseAppender(string connString)
	{
	PatternLayout layout = GetDefaultLayout();
	_sqlDatabaseAppender = new AdoNetAppender();
	_sqlDatabaseAppender.Layout = layout;
	_sqlDatabaseAppender.UseTransactions = false;
	_sqlDatabaseAppender.BufferSize = 1;
	
	_sqlDatabaseAppender.CommandType = System.Data.CommandType.Text;
	_sqlDatabaseAppender.ConnectionString = connString;
	_sqlDatabaseAppender.CommandText = "INSERT INTO Log
	([Date],[Level],[Thread],[Logger],[Message],[Exception]) VALUES
	(@log_date, @log_level, @thread, @logger, @message,
@exception)";
	AdoNetAppenderParameter logDate = new AdoNetAppenderParameter();
	RawTimeStampLayout dateLayout = new RawTimeStampLayout();
	logDate.ParameterName = "@log_date";
	logDate.Layout = dateLayout;
	logDate.DbType = System.Data.DbType.DateTime;
	_sqlDatabaseAppender.AddParameter(logDate);
	AdoNetAppenderParameter logThread = new
AdoNetAppenderParameter();
	logThread.ParameterName = "@thread";
	logThread.Size = 255;
	logThread.DbType = System.Data.DbType.String;
	_sqlDatabaseAppender.AddParameter(logThread);
	AdoNetAppenderParameter logLevel = new
AdoNetAppenderParameter();
	logLevel.ParameterName = "@log_level";
	logLevel.Size = 50;
	logLevel.DbType = System.Data.DbType.String;
	_sqlDatabaseAppender.AddParameter(logLevel);
	AdoNetAppenderParameter logLogger = new
AdoNetAppenderParameter();
	logLogger.ParameterName = "@logger";
	logLogger.Size = 255;
	logLogger.DbType = System.Data.DbType.String;
	_sqlDatabaseAppender.AddParameter(logLogger);
	AdoNetAppenderParameter logMessage = new
AdoNetAppenderParameter();
	logMessage.ParameterName = "@message";
	logMessage.Size = 4000;
	logMessage.DbType = System.Data.DbType.String;
	_sqlDatabaseAppender.AddParameter(logMessage);
	AdoNetAppenderParameter logException = new
AdoNetAppenderParameter();
	logException.ParameterName = "@exception";
	logException.Size = 2000;
	logException.DbType = System.Data.DbType.String;
	_sqlDatabaseAppender.AddParameter(logException);
	_sqlDatabaseAppender.ActivateOptions();
	
	BasicConfigurator.Configure(_sqlDatabaseAppender);
	}
	
	Any help would be great.
	
	James.
	
	
	
	scanned by MessageLabs [www.messagelabs.com]
	
	
	




-- 
Cheers,

w://

scanned by MessageLabs [www.messagelabs.com]


Re: Using AdoNetAppender

Posted by Wayne Douglas <wa...@codingvista.com>.
AppConfig is much simpler - you should start with that then convert to this
if you need to - not sure why you'd need to tho?

On Mon, Jun 15, 2009 at 4:31 PM, James Green <Ja...@occam-dm.com>wrote:

> I may have to try that.  Currently it just fails with an "Oject
> reference not set to an instance of an object."
>
> Thanks,
>
> James.
>
> -----Original Message-----
> From: Matt Lund [mailto:mlund@control4.com]
> Sent: 15 June 2009 16:28
> To: Log4NET User
> Subject: RE: Using AdoNetAppender
>
> Have you already gotten AdoNetAppender to work from a app.config /
> web.config first?  If not, I'd suggest getting that to work first.  You
> may learn something in that process and it'll spark a realization of
> what you're missing in the from-code approach?
>
> -----Original Message-----
> From: James Green [mailto:James.Green@occam-dm.com]
> Sent: Monday, June 15, 2009 9:26 AM
> To: Log4NET User
> Subject: Using AdoNetAppender
>
> Hi All,
>
> I've spent about 4 hours today trying to get this working and have
> totally failed so far.
>
> I can't even really find much info on how to configure this purely in
> Code.  In fact there is precious little I can find on the net in fact.
>
> Here is the code I'm using the set up the AdoNetAppender in my app:
>
>
> public static void ConfigureDatabaseAppender(string connString)
> {
> PatternLayout layout = GetDefaultLayout();
> _sqlDatabaseAppender = new AdoNetAppender();
> _sqlDatabaseAppender.Layout = layout;
> _sqlDatabaseAppender.UseTransactions = false;
> _sqlDatabaseAppender.BufferSize = 1;
>
> _sqlDatabaseAppender.CommandType = System.Data.CommandType.Text;
> _sqlDatabaseAppender.ConnectionString = connString;
> _sqlDatabaseAppender.CommandText = "INSERT INTO Log
> ([Date],[Level],[Thread],[Logger],[Message],[Exception]) VALUES
> (@log_date, @log_level, @thread, @logger, @message, @exception)";
> AdoNetAppenderParameter logDate = new AdoNetAppenderParameter();
> RawTimeStampLayout dateLayout = new RawTimeStampLayout();
> logDate.ParameterName = "@log_date";
> logDate.Layout = dateLayout;
> logDate.DbType = System.Data.DbType.DateTime;
> _sqlDatabaseAppender.AddParameter(logDate);
> AdoNetAppenderParameter logThread = new AdoNetAppenderParameter();
> logThread.ParameterName = "@thread";
> logThread.Size = 255;
> logThread.DbType = System.Data.DbType.String;
> _sqlDatabaseAppender.AddParameter(logThread);
> AdoNetAppenderParameter logLevel = new AdoNetAppenderParameter();
> logLevel.ParameterName = "@log_level";
> logLevel.Size = 50;
> logLevel.DbType = System.Data.DbType.String;
> _sqlDatabaseAppender.AddParameter(logLevel);
> AdoNetAppenderParameter logLogger = new AdoNetAppenderParameter();
> logLogger.ParameterName = "@logger";
> logLogger.Size = 255;
> logLogger.DbType = System.Data.DbType.String;
> _sqlDatabaseAppender.AddParameter(logLogger);
> AdoNetAppenderParameter logMessage = new AdoNetAppenderParameter();
> logMessage.ParameterName = "@message";
> logMessage.Size = 4000;
> logMessage.DbType = System.Data.DbType.String;
> _sqlDatabaseAppender.AddParameter(logMessage);
> AdoNetAppenderParameter logException = new AdoNetAppenderParameter();
> logException.ParameterName = "@exception";
> logException.Size = 2000;
> logException.DbType = System.Data.DbType.String;
> _sqlDatabaseAppender.AddParameter(logException);
> _sqlDatabaseAppender.ActivateOptions();
>
> BasicConfigurator.Configure(_sqlDatabaseAppender);
> }
>
> Any help would be great.
>
> James.
>
>
> scanned by MessageLabs [www.messagelabs.com]
>
>
>


-- 
Cheers,

w://

RE: Using AdoNetAppender

Posted by James Green <Ja...@occam-dm.com>.
I may have to try that.  Currently it just fails with an "Oject
reference not set to an instance of an object."

Thanks,

James. 

-----Original Message-----
From: Matt Lund [mailto:mlund@control4.com] 
Sent: 15 June 2009 16:28
To: Log4NET User
Subject: RE: Using AdoNetAppender

Have you already gotten AdoNetAppender to work from a app.config /
web.config first?  If not, I'd suggest getting that to work first.  You
may learn something in that process and it'll spark a realization of
what you're missing in the from-code approach?

-----Original Message-----
From: James Green [mailto:James.Green@occam-dm.com] 
Sent: Monday, June 15, 2009 9:26 AM
To: Log4NET User
Subject: Using AdoNetAppender

Hi All,
 
I've spent about 4 hours today trying to get this working and have
totally failed so far.
 
I can't even really find much info on how to configure this purely in
Code.  In fact there is precious little I can find on the net in fact.
 
Here is the code I'm using the set up the AdoNetAppender in my app:
 
 
public static void ConfigureDatabaseAppender(string connString)
{
PatternLayout layout = GetDefaultLayout();
_sqlDatabaseAppender = new AdoNetAppender();
_sqlDatabaseAppender.Layout = layout;
_sqlDatabaseAppender.UseTransactions = false;
_sqlDatabaseAppender.BufferSize = 1;
 
_sqlDatabaseAppender.CommandType = System.Data.CommandType.Text;
_sqlDatabaseAppender.ConnectionString = connString;
_sqlDatabaseAppender.CommandText = "INSERT INTO Log
([Date],[Level],[Thread],[Logger],[Message],[Exception]) VALUES
(@log_date, @log_level, @thread, @logger, @message, @exception)";
AdoNetAppenderParameter logDate = new AdoNetAppenderParameter();
RawTimeStampLayout dateLayout = new RawTimeStampLayout();
logDate.ParameterName = "@log_date";
logDate.Layout = dateLayout;
logDate.DbType = System.Data.DbType.DateTime;
_sqlDatabaseAppender.AddParameter(logDate);
AdoNetAppenderParameter logThread = new AdoNetAppenderParameter();
logThread.ParameterName = "@thread";
logThread.Size = 255;
logThread.DbType = System.Data.DbType.String;
_sqlDatabaseAppender.AddParameter(logThread);
AdoNetAppenderParameter logLevel = new AdoNetAppenderParameter();
logLevel.ParameterName = "@log_level";
logLevel.Size = 50;
logLevel.DbType = System.Data.DbType.String;
_sqlDatabaseAppender.AddParameter(logLevel);
AdoNetAppenderParameter logLogger = new AdoNetAppenderParameter();
logLogger.ParameterName = "@logger";
logLogger.Size = 255;
logLogger.DbType = System.Data.DbType.String;
_sqlDatabaseAppender.AddParameter(logLogger);
AdoNetAppenderParameter logMessage = new AdoNetAppenderParameter();
logMessage.ParameterName = "@message";
logMessage.Size = 4000;
logMessage.DbType = System.Data.DbType.String;
_sqlDatabaseAppender.AddParameter(logMessage);
AdoNetAppenderParameter logException = new AdoNetAppenderParameter();
logException.ParameterName = "@exception";
logException.Size = 2000;
logException.DbType = System.Data.DbType.String;
_sqlDatabaseAppender.AddParameter(logException);
_sqlDatabaseAppender.ActivateOptions();
 
BasicConfigurator.Configure(_sqlDatabaseAppender);
}

Any help would be great.

James.


scanned by MessageLabs [www.messagelabs.com]



RE: Using AdoNetAppender

Posted by Matt Lund <ml...@control4.com>.
Have you already gotten AdoNetAppender to work from a app.config /
web.config first?  If not, I'd suggest getting that to work first.  You
may learn something in that process and it'll spark a realization of
what you're missing in the from-code approach?

-----Original Message-----
From: James Green [mailto:James.Green@occam-dm.com] 
Sent: Monday, June 15, 2009 9:26 AM
To: Log4NET User
Subject: Using AdoNetAppender

Hi All,
 
I've spent about 4 hours today trying to get this working and have
totally failed so far.
 
I can't even really find much info on how to configure this purely in
Code.  In fact there is precious little I can find on the net in fact.
 
Here is the code I'm using the set up the AdoNetAppender in my app:
 
 
public static void ConfigureDatabaseAppender(string connString)
{
PatternLayout layout = GetDefaultLayout();
_sqlDatabaseAppender = new AdoNetAppender();
_sqlDatabaseAppender.Layout = layout;
_sqlDatabaseAppender.UseTransactions = false;
_sqlDatabaseAppender.BufferSize = 1;
 
_sqlDatabaseAppender.CommandType = System.Data.CommandType.Text;
_sqlDatabaseAppender.ConnectionString = connString;
_sqlDatabaseAppender.CommandText = "INSERT INTO Log
([Date],[Level],[Thread],[Logger],[Message],[Exception]) VALUES
(@log_date, @log_level, @thread, @logger, @message, @exception)";
AdoNetAppenderParameter logDate = new AdoNetAppenderParameter();
RawTimeStampLayout dateLayout = new RawTimeStampLayout();
logDate.ParameterName = "@log_date";
logDate.Layout = dateLayout;
logDate.DbType = System.Data.DbType.DateTime;
_sqlDatabaseAppender.AddParameter(logDate);
AdoNetAppenderParameter logThread = new AdoNetAppenderParameter();
logThread.ParameterName = "@thread";
logThread.Size = 255;
logThread.DbType = System.Data.DbType.String;
_sqlDatabaseAppender.AddParameter(logThread);
AdoNetAppenderParameter logLevel = new AdoNetAppenderParameter();
logLevel.ParameterName = "@log_level";
logLevel.Size = 50;
logLevel.DbType = System.Data.DbType.String;
_sqlDatabaseAppender.AddParameter(logLevel);
AdoNetAppenderParameter logLogger = new AdoNetAppenderParameter();
logLogger.ParameterName = "@logger";
logLogger.Size = 255;
logLogger.DbType = System.Data.DbType.String;
_sqlDatabaseAppender.AddParameter(logLogger);
AdoNetAppenderParameter logMessage = new AdoNetAppenderParameter();
logMessage.ParameterName = "@message";
logMessage.Size = 4000;
logMessage.DbType = System.Data.DbType.String;
_sqlDatabaseAppender.AddParameter(logMessage);
AdoNetAppenderParameter logException = new AdoNetAppenderParameter();
logException.ParameterName = "@exception";
logException.Size = 2000;
logException.DbType = System.Data.DbType.String;
_sqlDatabaseAppender.AddParameter(logException);
_sqlDatabaseAppender.ActivateOptions();
 
BasicConfigurator.Configure(_sqlDatabaseAppender);
}

Any help would be great.

James.