log4net 没有写入两个 RollingFileAppenders
log4net is not writing to two RollingFileAppenders
这是我的应用配置
<log4net>
<root>
<level value="ALL" />
<appender-ref ref="RollingFileAppender" />
</root>
<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
<file type='log4net.Util.PatternString' value='%property{LogPath}\%property{LogFileName}' />
<appendToFile value="true" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="5" />
<maximumFileSize value="10MB" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date %level [%thread] - %message%newline" />
</layout>
</appender>
<appender name="PerformanceLogger" type="log4net.Appender.RollingFileAppender">
<file type='log4net.Util.PatternString' value='%property{LogPath}\%property{PerformanceLogFileName}' />
<appendToFile value="true" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="1" />
<maximumFileSize value="2MB" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date %level [%thread] - %message%newline" />
</layout>
</appender>
<logger Name="PerformanceLogger" additivity="false">
<level value="ALL"/>
<appender-ref ref="PerformanceLogger"/>
</logger>
</log4net>
当我尝试获取记录器并写入时。它只是为 PerformanceLogger 创建文件,但不会写入它。
log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
performaceLog = LogManager.GetLogger("PerformanceLogger");
但是我的 log.Info("test");
工作正常,它创建了一个文件并写入了它。
有什么建议吗?
PerformanceLogger 的记录器定义不正确 - 您使用 Name
而不是 name
来定义记录器的名称。将其更改为以下内容,它应该可以正常工作:
...
<logger name="PerformanceLogger" additivity="false">
<level value="ALL"/>
<appender-ref ref="PerformanceLogger"/>
</logger>
...
这是我的应用配置
<log4net>
<root>
<level value="ALL" />
<appender-ref ref="RollingFileAppender" />
</root>
<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
<file type='log4net.Util.PatternString' value='%property{LogPath}\%property{LogFileName}' />
<appendToFile value="true" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="5" />
<maximumFileSize value="10MB" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date %level [%thread] - %message%newline" />
</layout>
</appender>
<appender name="PerformanceLogger" type="log4net.Appender.RollingFileAppender">
<file type='log4net.Util.PatternString' value='%property{LogPath}\%property{PerformanceLogFileName}' />
<appendToFile value="true" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="1" />
<maximumFileSize value="2MB" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date %level [%thread] - %message%newline" />
</layout>
</appender>
<logger Name="PerformanceLogger" additivity="false">
<level value="ALL"/>
<appender-ref ref="PerformanceLogger"/>
</logger>
</log4net>
当我尝试获取记录器并写入时。它只是为 PerformanceLogger 创建文件,但不会写入它。
log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
performaceLog = LogManager.GetLogger("PerformanceLogger");
但是我的 log.Info("test");
工作正常,它创建了一个文件并写入了它。
有什么建议吗?
PerformanceLogger 的记录器定义不正确 - 您使用 Name
而不是 name
来定义记录器的名称。将其更改为以下内容,它应该可以正常工作:
...
<logger name="PerformanceLogger" additivity="false">
<level value="ALL"/>
<appender-ref ref="PerformanceLogger"/>
</logger>
...