0
<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] &lt;%X{diagnostic}&gt; - %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] &lt;%X{DR} %X{NA}&gt; - %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] &lt;%X{DR} %X{NA}&gt; - %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] &lt;%X{auth}&gt; - %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>

' CODE New Logger().Info("写一些信息")

当我调用上面的代码时,它不会将任何输出写入 data_integrationTransaction.log 文件。但是 New Logger().Error("Write some error") 工作正常。

我感谢您的支持。

4

1 回答 1

1

获取记录器的推荐方法如下所示而不是您拥有的。我会在 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>元素来阐明附加程序的默认级别。

于 2012-04-23T17:31:26.653 回答