简体   繁体   中英

Logging using ORM (log4net and OpenAccess)

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM