1

Based previous experience and research, I implemented logging at the workplace using log4Net.

However, there was general preference to use a custom logger when log4net was presented in our development meetings. The reason was in order to use the generated code from Telerik's ORM instead of specifying the insert query in the configuration file.

<appender name="ADONetAppender" type="log4net.Appender.AdoNetAppender">
   <bufferSize value="1"/>
   <connectionType value="MySql.Data.MySqlClient.MySqlConnection, MySql.Data" />
   <connectionStringName value="Test"/>
   <commandText value="INSERT INTO Log (UniqueId,Date,UserId,Thread,level,Logger,Message,Exception)     VALUES (UUID(),?log_date,?userid,?thread,?log_level,?logger,?message,?exception)" />
   ...

What is your advice? Can we create a custom appender for this purpose? Should we go for the custom logger?

For information, there are positive and negative views on custom loggers here.

Thanks

Community
  • 1
  • 1
Nishzone
  • 101
  • 1
  • 4

1 Answers1

0

You can create a custom logger, and it can use any mechanism you like to log stuff. Personally I found the AdoNetAppender perfectly performant.

However having worked supporting enterprise operations I'd strongly recommend that you use the lowest impedance technique to log your messages. Logs come into their own with debugging production systems. I'd avoid writing an appender for the sake of 'db access pattern consistency'.

If you are having db, ORM, OS or networking problems the last thing you need is for your logger not to be working. File, Windows Debug messges and ETW logging is what I recommend in the first instance and this can be backed up with DB logging and to make it safer I'd put the db logging into at least a different db - so not to affect your production systems. Preferably it would be on local server where network connectivity won't come into play.

Edit:

If you really want to you can derive a class from AdoNetAppender and then override the CommandText Property to be custom. There is an example on here that I can't seem to place, that does this with connectionstring.

Preet Sangha
  • 64,563
  • 18
  • 145
  • 216
  • When you say 'any mechanism', can I use the AdoNetAppender without specifying the insert query in the configuration file? I would like the functionality/performance of Log4Net and satisfy the team requirements. Thanks for the suggestion. I will do some research and consider a different database. – Nishzone Mar 10 '13 at 06:32
  • Yes, I have seen the examples where you can override the connection string. It was used before log4net had the "connectionStringName" property. I had considered using the same method for the commandtext but it will still not use the data transfer objects generated that the team required. A custom logger seem to be the only solution right now. – Nishzone Mar 10 '13 at 09:33