tags:

views:

432

answers:

2

I am using NHibernate and log4net. This is a snapshot of my error log file, using a release version of my software:

INFO 2009-04-28 03:07:06 - processing cascade NHibernate.Engine.CascadingAction+SaveUpdateCascadingAction for: bpojob.Generated.BusinessObjects.Job
INFO 2009-04-28 03:07:06 - cascade NHibernate.Engine.CascadingAction+SaveUpdateCascadingAction for collection: bpojob.Generated.BusinessObjects.Job.JobItems
DEBUG2009-04-28 03:07:06 - cascading to saveOrUpdate: bpojob.Generated.BusinessObjects.JobItem
DEBUG2009-04-28 03:07:06 - unsaved-value: 0
DEBUG2009-04-28 03:07:06 - transient instance of: bpojob.Generated.BusinessObjects.JobItem
DEBUG2009-04-28 03:07:06 - saving transient instance
DEBUG2009-04-28 03:07:06 - saving [bpojob.Generated.BusinessObjects.JobItem#<null>]
DEBUG2009-04-28 03:07:06 - executing insertions
DEBUG2009-04-28 03:07:06 - executing identity-insert immediately
DEBUG2009-04-28 03:07:06 - Inserting entity: bpojob.Generated.BusinessObjects.JobItem (native id)
DEBUG2009-04-28 03:07:06 - Opened new IDbCommand, open IDbCommands: 1
DEBUG2009-04-28 03:07:06 - Building an IDbCommand object for the SqlString: INSERT INTO job_items (FileName, Job_Id, Status) VALUES (?, ?, ?)
DEBUG2009-04-28 03:07:06 - Dehydrating entity: [bpojob.Generated.BusinessObjects.JobItem#<null>]
DEBUG2009-04-28 03:07:06 - binding 'Blue hills.jpg' to parameter: 0
DEBUG2009-04-28 03:07:06 - binding '8' to parameter: 1
DEBUG2009-04-28 03:07:06 - binding '1' to parameter: 2
DEBUG2009-04-28 03:07:06 - INSERT INTO job_items (FileName, Job_Id, Status) VALUES (?p0, ?p1, ?p2); ?p0 = 'Blue hills.jpg', ?p1 = '8', ?p2 = '1'
DEBUG2009-04-28 03:07:06 - Obtaining IDbConnection from Driver
DEBUG2009-04-28 03:07:06 - Closed IDbCommand, open IDbCommands: 0
DEBUG2009-04-28 03:07:06 - aggressively releasing database connection
DEBUG2009-04-28 03:07:06 - Closing connection
DEBUG2009-04-28 03:07:06 - could not insert: [bpojob.Generated.BusinessObjects.JobItem]
[ INSERT INTO job_items (FileName, Job_Id, Status) VALUES (?p0, ?p1, ?p2) ]

MySql.Data.MySqlClient.MySqlException: Duplicate entry 'Blue hills.jpg' for key 'Unique'
   at MySql.Data.MySqlClient.MySqlStream.ReadPacket()
   at MySql.Data.MySqlClient.NativeDriver.ReadResult(UInt64& affectedRows, Int64& lastInsertId)
   at MySql.Data.MySqlClient.MySqlDataReader.GetResultSet()
   at MySql.Data.MySqlClient.MySqlDataReader.NextResult()
   at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior)
   at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader()
   at MySql.Data.MySqlClient.MySqlCommand.ExecuteNonQuery()
   at NHibernate.AdoNet.AbstractBatcher.ExecuteNonQuery(IDbCommand cmd)
   at NHibernate.Id.Insert.AbstractSelectingDelegate.PerformInsert(SqlCommandInfo insertSQL, ISessionImplementor session, IBinder binder)

As you can see, all the info, debug and exception are cobbled together, making it extremely hard to sift through the file and look for information once bugs come out.

I want to put all the exception info into a file, and put other info into another file. And I want to exclude the debug information is release mode. How to do this?

A: 

Can't you just use a Log Parser to filter/order the data in any way you choose?

Log4Net Dashboard is a good tool for this purpose (and it has a free developer version).

Mitch Wheat
+1  A: 

In your log4net.xml use a different file appender logger for Error and Warning

See here for more info

Preet Sangha