zoukankan      html  css  js  c++  java
  • log4net

    程序启动:

    #region Log4net注册
            private void RegisterLog4net()
            {
                try
                {
                    string configfile = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "log4net.config");
                    if (!System.IO.File.Exists(configfile))
                    {
                        return;
                    }
                    log4net.Config.XmlConfigurator.Configure(new System.IO.FileInfo(configfile));
                    log = LogManager.GetLogger(this.GetType());
                }
                catch
                {
                }
            } 
            #endregion

    配置文件:log4net.config

    <?xml version="1.0"?>
    <configuration>

    <configSections>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
    </configSections>

    <log4net>
    <appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
    <param name="File" value="./log/Debug.log"/>
    <appendToFile value="true"/>
    <rollingStyle value="Composite"/>
    <maxSizeRollBackups value="100"/>
    <maximumFileSize value="1MB"/>
    <staticLogFileName value="false"/>
    <param name="DatePattern" value="yyyyMM\\yyyyMMdd\\&quot;Service.log&quot;"/>
    <layout type="log4net.Layout.PatternLayout">
    <header value="************ System Start **********&#13;&#10;"/>
    <footer value="************ System End ************&#13;&#10;"/>
    <conversionPattern value="%d %-5p [%c] (line:%L) %n%m%n%n"/>
    </layout>
    </appender>
    <appender name="InfoRollingFileAppender" type="log4net.Appender.RollingFileAppender">
    <param name="File" value="./log/Info.log"/>
    <appendToFile value="true"/>
    <rollingStyle value="Composite"/>
    <maxSizeRollBackups value="100"/>
    <maximumFileSize value="1MB"/>
    <staticLogFileName value="false"/>
    <param name="DatePattern" value="yyyyMM\\yyyyMMdd\\&quot;Service.Info.log&quot;"/>
    <layout type="log4net.Layout.PatternLayout">
    <header value="************ System Start **********&#13;&#10;"/>
    <footer value="************ System End ************&#13;&#10;"/>
    <conversionPattern value="#%d %-5p [%c] (line:%L) %n%m%n%n"/>
    </layout>
    <filter type="log4net.Filter.LevelRangeFilter">
    <param name="LevelMin" value="INFO"/>
    <param name="LevelMax" value="INFO"/>
    </filter>
    </appender>
    <appender name="WarnRollingFileAppender" type="log4net.Appender.RollingFileAppender">
    <file value="./log/Warn.log"/>
    <appendToFile value="true"/>
    <rollingStyle value="Composite"/>
    <param name="DatePattern" value="yyyyMM\\yyyyMMdd\\&quot;Service.Warn.log&quot;"/>
    <maxSizeRollBackups value="100"/>
    <maximumFileSize value="1MB"/>
    <staticLogFileName value="false"/>
    <layout type="log4net.Layout.PatternLayout">
    <header value="************ System Start **********&#13;&#10;"/>
    <footer value="************ System End ************&#13;&#10;"/>
    <conversionPattern value="!%d %-5p [%c] (line:%L) %m%n"/>
    </layout>
    <filter type="log4net.Filter.LevelRangeFilter">
    <param name="LevelMin" value="WARN"/>
    <param name="LevelMax" value="WARN"/>
    </filter>
    </appender>
    <appender name="ErrorRollingFileAppender" type="log4net.Appender.RollingFileAppender">
    <file value="./log/Error.log"/>
    <appendToFile value="true"/>
    <rollingStyle value="Composite"/>
    <param name="DatePattern" value="yyyyMM\\yyyyMMdd\\&quot;Service.Error.log&quot;"/>
    <maxSizeRollBackups value="100"/>
    <maximumFileSize value="1MB"/>
    <staticLogFileName value="false"/>
    <layout type="log4net.Layout.PatternLayout">
    <header value="************ System Start **********&#13;&#10;"/>
    <footer value="************ System End ************&#13;&#10;"/>
    <conversionPattern value="x!!%d %-5p [%c] (line:%L) %m%n"/>
    </layout>
    <filter type="log4net.Filter.LevelRangeFilter">
    <param name="LevelMin" value="ERROR"/>
    <param name="LevelMax" value="FATAL"/>
    </filter>
    </appender>
    <root>
    <level value="ALL"/>
    <appender-ref ref="RollingFileAppender"/>
    <appender-ref ref="InfoRollingFileAppender"/>
    <appender-ref ref="WarnRollingFileAppender"/>
    <appender-ref ref="ErrorRollingFileAppender"/>
    </root>
    </log4net>
    </configuration>

  • 相关阅读:
    Visual Studio for Mac 2017 初体验
    利用栈求表达式的值
    Problem C: ChongQueue
    Problem G: ZL's Prob.2
    Problem F: ZL's Prob.1
    Problem B: ChongBit
    HDU 5156
    SHUOJ 1771
    OpenGL学习整理------着色器
    OpenGL ES着色器语言----------------储存修饰符
  • 原文地址:https://www.cnblogs.com/Rannie/p/3903987.html
Copyright © 2011-2022 走看看