我正在尝试将新的滚动文件appender添加到现有的log4net配置中。我一直在关注S.O.的问题。并查看文档,但我似乎无法看到我的问题在哪里。
问题是它创建了文件但从不写入文件。我能想到的是,我以某种方式误解了层次结构是如何运作的?如果我附加了一个调试器,我可以看到该行被写入控制台,但即使我进行了测试部署,日志文件文档也从未写入任何内容。还有其他问题,但是他们都有关于levelMin或类似的问题。我已经尝试将配置设置为ALL,也没有帮助。
这是完整的配置,所以你可以看到我在说什么。
<?xml version="1.0" encoding="utf-8" ?>
<log4net debug="true">
<root>
<level value="ALL"/>
<appender-ref ref="CompassServiceTraceAppender" />
<appender-ref ref="EventLogAppender" />
<appender-ref ref="DbAppender" />
</root>
<logger name="Compass.Service.Implementation.EdiService">
<level value="ALL"/>
<appender-ref ref="EventProcessingFailureLogFileAppender" />
</logger>
<logger name="Compass.Service.Implementation.PhoneService">
<level value="ALL"/>
<appender-ref ref="LivevoxResultsReprocessorAppender"/>
</logger>
<logger name="DocumentImportLogger">
<level value="ALL"/>
<appender-ref ref="DocumentLogFileAppender" />
</logger>
<logger name="NHibernate">
<level value="ERROR"/>
<appender-ref ref="CompassServiceTraceAppender" />
<appender-ref ref="EventLogAppender" />
<appender-ref ref="DbAppender" />
</logger>
<appender name="DbAppender" type="log4net.Appender.AdoNetAppender">
<threshold value="WARN" />
<bufferSize value="1" />
<connectionType value="System.Data.SqlClient.SqlConnection, System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<connectionString value="data source=.;initial catalog=logDb;integrated security=True;persist security info=True;" />
<commandText value="INSERT INTO ErrorLog ([Date],[Thread],[Level],[Logger],[Message],[Exception],[Environment],[Application],[User],[ObjectName],[ObjectId],[SupportId]) VALUES (@log_date, @thread, @log_level, @logger, @message, @exception, 'localhost','Compass BB', @user, @objectName, @objectId, @supportId)" />
<parameter>
<parameterName value="@log_date" />
<dbType value="DateTime" />
<layout type="log4net.Layout.PatternLayout" value="%date{yyyy'-'MM'-'dd HH':'mm':'ss'.'fff}" />
</parameter>
<parameter>
<parameterName value="@thread" />
<dbType value="String" />
<size value="255" />
<layout type="log4net.Layout.PatternLayout" value="%thread" />
</parameter>
<parameter>
<parameterName value="@log_level" />
<dbType value="String" />
<size value="50" />
<layout type="log4net.Layout.PatternLayout" value="%level" />
</parameter>
<parameter>
<parameterName value="@logger" />
<dbType value="String" />
<size value="255" />
<layout type="log4net.Layout.PatternLayout" value="%logger" />
</parameter>
<parameter>
<parameterName value="@message" />
<dbType value="String" />
<size value="4000" />
<layout type="log4net.Layout.PatternLayout" value="%message" />
</parameter>
<parameter>
<parameterName value="@exception" />
<dbType value="String" />
<size value="4000" />
<layout type="log4net.Layout.PatternLayout" value="%exception" />
</parameter>
<parameter>
<parameterName value="@user" />
<dbType value="String" />
<size value="50" />
<layout type="log4net.Layout.PatternLayout" value="%property{CurrentUser}" />
</parameter>
<parameter>
<parameterName value="@objectName" />
<dbType value="String" />
<size value="50" />
<layout type="log4net.Layout.PatternLayout" value="%property{ObjectName}" />
</parameter>
<parameter>
<parameterName value="@objectId" />
<dbType value="String" />
<size value="50" />
<layout type="log4net.Layout.PatternLayout" value="%property{ObjectId}" />
</parameter>
<parameter>
<parameterName value="@supportId" />
<dbType value="String" />
<size value="50" />
<layout type="log4net.Layout.PatternLayout" value="%property{SupportId}" />
</parameter>
</appender>
<appender name="CompassServiceTraceAppender" type="log4net.Appender.TraceAppender">
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%level - %message%newline" />
</layout>
</appender>
<appender name="EventLogAppender" type="log4net.Appender.EventLogAppender">
<threshold value="WARN" />
<param name="ApplicationName" value="Compass Best Benefits Service Host" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date %level %logger %newline User: %property{CurrentUser} Object: %property{ObjectName} Id: %property{ObjectId} %newline %message %newline %exception"/>
</layout>
</appender>
<appender name="EventProcessingFailureLogFileAppender" type="log4net.Appender.RollingFileAppender">
<threshold value="ALL" />
<param name="File" value="c:\logs\EventProcessingFailure_log.txt" />
<param name="AppendToFile" value="true" />
<param name="RollingStyle" value="Date" />
<param name="DatePattern" value="yyyy.MM.dd" />
<param name="StaticLogFileName" value="true" />
<param name="maxSizeRollBackups" value="10" />
<param name="maximumFileSize" value="1000KB" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date %level %logger - %message %newline %exception" />
</layout>
</appender>
<appender name="LivevoxResultsReprocessorAppender" type="log4net.Appender.RollingFileAppender">
<threshold value="ALL" />
<param name="File" value="c:\logs\Livevoxreprocessor.txt" />
<param name="AppendToFile" value="true" />
<param name="RollingStyle" value="Date" />
<param name="DatePattern" value="yyyy.MM.dd" />
<param name="StaticLogFileName" value="true" />
<param name="maxSizeRollBackups" value="10" />
<param name="maximumFileSize" value="1000KB" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%message %newline" />
</layout>
</appender>
<!--DocumentLogFileAppender-->
<appender name="DocumentLogFileAppender" type="log4net.Appender.RollingFileAppender">
<threshold value="ALL" />
<param name="File" value="c:\logs\DocumentLog.txt" />
<param name="AppendToFile" value="true" />
<param name="RollingStyle" value="Date" />
<param name="DatePattern" value="yyyy.MM.dd" />
<param name="StaticLogFileName" value="true" />
<param name="maxSizeRollBackups" value="10" />
<param name="maximumFileSize" value="1000KB" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%message %newline" />
</layout>
</appender>
</log4net>
这是代码示例。
private static readonly HALogger Logger = new HALogger("DocumentImportLogger");
//which calls
public HALogger(string loggerName)
{
_logger = LogManager.GetLogger(loggerName);
}
//Then to log.
Logger.Info(string.Format("Checking for new documents - LastDocumentId: {0}", LastDocInfo.LastDocumentId));
答案 0 :(得分:1)
您的配置文件对我来说很好。
问题是log4net在默认情况下默默地忽略配置错误而只是默默地失败 - 这对于日志记录框架来说是一个明智的设计选择,但有时会令人沮丧。
您可以尝试启用内部调试并以编程方式检查配置错误。
请参阅the log4net faq =&gt;相关部分是:
“How do I enable log4net internal debugging?”
“How can I evaluate configuration errors at runtime?”
另外,请添加一个代码示例,说明如何获取记录器并尝试写入。