<configuration>
<!-- Register the section handler for the log4net section -->
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net"/>
</configSections>
<!-- This section contains the log4net configuration settings -->
<log4net debug="true">
<!-- Define the default appender -->
<appender name="PowerFAIDSLogger" type="log4net.Appender.RollingFileAppender,log4net">
<file type="log4net.Util.PatternString" value="%env{ALLUSERSPROFILE}\Company Name\App Name\data_integration.log"/>
<param name="AppendToFile" value="true"/>
<param name="RollingStyle" value="Size"/>
<param name="MaxSizeRollBackups" value="10"/>
<param name="MaximumFileSize" value="512KB"/>
<param name="StaticLogFileName" value="true"/>
<layout type="log4net.Layout.PatternLayout,log4net">
<param name="ConversionPattern" value="{%d{MMM-dd-yyyy} ~ %t} %10r %-5p [%x] <%X{diagnostic}> - %m%n"/>
</layout>
</appender>
<appender name="PerformanceLogger" type="log4net.Appender.RollingFileAppender,log4net">
<file type="log4net.Util.PatternString" value="%env{ALLUSERSPROFILE}\Company Name\App Name\performance.log"/>
<param name="AppendToFile" value="true"/>
<param name="RollingStyle" value="Size"/>
<param name="MaxSizeRollBackups" value="10"/>
<param name="MaximumFileSize" value="512KB"/>
<param name="StaticLogFileName" value="true"/>
<layout type="log4net.Layout.PatternLayout,log4net">
<param name="ConversionPattern" value="{%d{MMM-dd-yyyy} ~ %t} %10r %-5p [%x] <%X{DR} %X{NA}> - %m%n"/>
</layout>
</appender>
<appender name="TransactionLogger" type="log4net.Appender.RollingFileAppender,log4net">
<file type="log4net.Util.PatternString" value="%env{ALLUSERSPROFILE}\Company Name\App Name\data_integrationTransaction.log"/>
<param name="AppendToFile" value="true"/>
<param name="RollingStyle" value="Size"/>
<param name="MaxSizeRollBackups" value="10"/>
<param name="MaximumFileSize" value="512KB"/>
<param name="StaticLogFileName" value="true"/>
<layout type="log4net.Layout.PatternLayout,log4net">
<param name="ConversionPattern" value="{%d{MMM-dd-yyyy} ~ %t} %10r %-5p [%x] <%X{DR} %X{NA}> - %m%n"/>
</layout>
</appender>
<!-- Define the email appender -->
<appender name="SMTPAppender" type="log4net.Appender.SMTPAppender">
<param name="To" value="someone@abc.com"/>
<param name="From" value="jdf@CompanyName.org"/>
<param name="Subject" value="App Name Error Message"/>
<param name="SMTPHost" value="ecogsdf.CompanyName.local"/>
<param name="LocationInfo" value="false"/>
<param name="BufferSize" value="512"/>
<param name="Lossy" value="true"/>
<evaluator type="log4net.spi.LevelEvaluator">
<param name="Threshold" value="WARN"/>
</evaluator>
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %-5p %c [%x] <%X{auth}> - %m%n"/>
</layout>
</appender>
<!-- Setup the loggers, add the appenders and set the default priority -->
<logger name="PerformanceLogger">
<priority value="ALL"/>
<appender-ref ref="PerformanceLogger"/>
</logger>
<logger name="App NameLogger">
<priority value="WARN"/>
<appender-ref ref="App NameLogger"/>
</logger>
<logger name="TransactionLogger">
<level value="INFO" />
<appender-ref ref="TransactionLogger"/>
</logger>
</log4net>
</configuration>
'代码 新记录器()。信息(“写一些信息”)
当我调用上面的代码时,它不会将任何输出写入data_integrationTransaction.log文件。但New Logger()。错误(“写一些错误”)工作正常。
感谢您的支持。
答案 0 :(得分:1)
获取记录器的推荐方法如here所示,而不是您拥有它。我会按照log4net文档再试一次。 ILog log = LogManager.GetLogger(“application-log”);
log.Info("Application Start");
log.Debug("This is a debug message");
if (log.IsDebugEnabled)
{
log.Debug("This is another debug message");
}
您可能还想设置一个<root>
元素来阐明您的appender的默认级别。