我正在使用NHibernate和log4net。这是我的错误日志文件的快照,使用我的软件的发布版本:
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)正如您所看到的,所有的info、debug和exception都是拼凑在一起的,这使得一旦出现bug就很难对文件进行筛选和查找信息。
我想把所有的异常信息放入一个文件,并将其他信息放到另一个文件中。而我想排除的调试信息是发布模式。怎么做?
发布于 2009-04-28 08:50:15
在您的log4net.xml中,使用不同的文件附录记录器进行错误和警告。
有关更多信息,请参见这里
发布于 2012-05-25 12:49:52
在下面的代码中,我使用了两个日志文件(一个用于调试,另一个用于致命)。
<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>发布于 2009-04-28 07:23:16
您不能使用以您选择的任何方式筛选/排序数据吗?
Log4Net指示板是实现这一目的的一个很好的工具(而且它有一个免费开发版本)。
https://stackoverflow.com/questions/796596
复制相似问题