zoukankan      html  css  js  c++  java
  • 利用log4添加log

    應用log4net.dll

    新建Global.asax,在cs文件中添加

     protected void Application_Start(object sender, EventArgs e)
            {
                #region system log init
                log4net.Config.XmlConfigurator.Configure(new System.IO.FileInfo(AppDomain.CurrentDomain.BaseDirectory + @"Log.config"));
                #endregion
            }

    添加Log.config文件

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
        <configSections>
            <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
        </configSections>
    
        <log4net>
            <root>
                <level value="Error"/>
            </root>
            <logger name="FatalLog">
                <level value="Fatal"/>
                <appender-ref ref="RollingLogFileAppender"/>
            </logger>
            <logger name="ErrorLog">
                <level value="Error"/>
                <appender-ref ref="RollingLogFileAppender"/>
            </logger>
            <logger name="WarnLog">
                <level value="Warn"/>
                <appender-ref ref="RollingLogFileAppender"/>
            </logger>
            <logger name="DebugLog">
                <level value="Debug"/>
                <appender-ref ref="RollingLogFileAppender"/>
            </logger>
            <logger name="HTGInfoLog">
                <level value="Info"/>
                <appender-ref ref="RollingHTGFileAppender"/>
            </logger>
            <logger name="F4GInfoLog">
                <level value="Info"/>
                <appender-ref ref="RollingF4GFileAppender"/>
            </logger>
            <logger name="InfoLog">
                <level value="Info"/>
                <appender-ref ref="RollingLogFileAppender"/>
            </logger>
        <logger name="RuleEngineLog">
          <level value="Info"/>
          <appender-ref ref="RollingRuleEngineLogFileAppender"/>
        </logger>
            
            <appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
                <!--輸出路徑-->
                <file value="Log"/>
                <param name="AppendToFile" value="true"/>
                <param name="MaxSizeRollBackups" value="1000"/>
                <param name="StaticLogFileName" value="false"/>
                <!--輸出按指定方式切換文件-->
                <param name="DatePattern" value="yyyyMMdd&quot;.log&quot;"/>
                <param name="RollingStyle" value="Composite"/><!--Date 按日期,Size 按大小-->
          <param name="maximumFileSize" value="10240KB" />
          <!--輸出LOG格式-->
                <lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
                <layout type="log4net.Layout.PatternLayout">
                    <param name="Header" value=""/>
                    <param name="ConversionPattern" value="%n------------LogName:%c --------------------------------------------%nTimestamp: %d %nClient: %X%nThread:%thread%nLevel: %p%n%m %n-------------------------------------------------------------------------%n"/>
                    <param name="Footer" value=""/>
                </layout>
                <!--輸出不同級別的LOG-->
                <!--<filter type="log4net.Filter.LevelRangeFilter">
            <param name="LevelMin" value="DEBUG"/>
    
            <param name="LevelMax" value="FATAL"/>
    
          </filter>-->
            </appender>
    
        <appender name="RollingRuleEngineLogFileAppender" type="log4net.Appender.RollingFileAppender">
          <!--Output path-->
          <file value="RuleEngineLog"/>
          <param name="AppendToFile" value="true"/>
          <param name="MaxSizeRollBackups" value="1000"/>
          <param name="StaticLogFileName" value="false"/>
          <!--Output file as specified switch-->
          <param name="DatePattern" value="&quot;RuleEngineLog&quot;yyyyMMdd&quot;.log&quot;"/>
          <param name="RollingStyle" value="Composite"/>
          <param name="maximumFileSize" value="10240KB" />
          <!--LOG output format-->
          <lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
          <layout type="log4net.Layout.PatternLayout">
            <param name="Header" value=""/>
            <param name="ConversionPattern" value="%n------------LogName:%c--------------------------------------------%n%m %n-----------------------------------------------------------------------------%n"/>
            <param name="Footer" value=""/>
          </layout>
        </appender>
        </log4net>
    </configuration>
    View Code
    111111
  • 相关阅读:
    intellij idea tomcat 启动不生成war包
    php中的Trait的使用方法
    c++ 命名的强制类型转换
    【递归与动态规划】正则表达式匹配
    c程序设计语言 by K&R(四)输入与输出
    c程序设计语言 by K&R(三)结构
    深入理解c语言指针与内存
    c程序设计语言 by K&R(一)一些c语言基础知识
    c程序设计语言 by K&R(二)指针与数组
    第一次在这里
  • 原文地址:https://www.cnblogs.com/whl4835349/p/6651503.html
Copyright © 2011-2022 走看看