Put the error information and error information in two different log files (Log4net)

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

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 info , debug and exception are gathered together, which makes it difficult to sift the file and search for information after errors occur.

I want to put all the exception information in a file and put other information in another file. And I want to exclude debug information release mode . How to do it?

+4
source share
3 answers

In your log4net.xml use a different file logger for errors and warnings

See here for more information.

+3
source

In the code below, I use two log files using two appender (one for Debug, the other for Fatal)

 <log4net> <appender name="FatalErrorLog" type="log4net.Appender.RollingFileAppender"> <file value="C:\temp\Host.log" /> <appendToFile value="true" /> <maximumFileSize value="10MB" /> <maxSizeRollBackups value="50" /> <rollingStyle value="Size" /> <layout type="log4net.Layout.PatternLayout"> <conversionPattern value="%date [%thread] %-5level %logger - %message%newline" /> </layout> <filter type="log4net.Filter.LevelRangeFilter"> <levelMin value="ERROR" /> <levelMax value="FATAL" /> </filter> </appender> <appender name="DebugLog" type="log4net.Appender.RollingFileAppender"> <file value="C:\temp\HostDebug.log" /> <appendToFile value="true" /> <maximumFileSize value="10MB" /> <maxSizeRollBackups value="50" /> <rollingStyle value="Size" /> <layout type="log4net.Layout.PatternLayout"> <conversionPattern value="%identity------%username------%date [%thread] %-5level %logger - %message%newline" /> </layout> <filter type="log4net.Filter.LevelRangeFilter"> <levelMin value="DEBUG" /> <levelMax value="ERROR" /> </filter> </appender> </log4net> 
+4
source

Can't you use Log Parser to filter / organize data in any way?

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

0
source

All Articles