• log4g net 配置


    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>

      <!-- Register a section handler for the log4net section -->
      <configSections>
        <section name="log4net" type="System.Configuration.IgnoreSectionHandler" />
      </configSections>

      <!-- This section contains the log4net configuration settings -->
      <log4net>

        <appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
          <layout type="log4net.Layout.PatternLayout">
            <conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
          </layout>
        </appender>

        <appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
          <file value="example.log" />
          <appendToFile value="true" />
          <maximumFileSize value="100KB" />
          <maxSizeRollBackups value="2" />

          <layout type="log4net.Layout.PatternLayout">
            <conversionPattern value="%level %thread %logger - %message%newline" />
          </layout>
        </appender>

        <appender name="MessageBoxAppender" type="SampleAppendersApp.Appender.MessageBoxAppender, SampleAppendersApp">

          <layout type="log4net.Layout.PatternLayout" value="%date [%thread] %-5level %logger [%ndc] &lt;%property{auth}&gt; - %message%newline"/>
          <titleLayout type="log4net.Layout.PatternLayout" value="LoggingEvent: %-5level %logger"/>
          <mapping>
            <level value="ERROR" />
            <icon value="Error" />
          </mapping>

        </appender>


        <appender name="FireEventAppender" type="SampleAppendersApp.Appender.FireEventAppender, SampleAppendersApp">
        </appender>

        <appender name="SimpleSmtpAppender" type="SampleAppendersApp.Appender.SimpleSmtpAppender, SampleAppendersApp">
          <layout type="log4net.Layout.PatternLayout" value="%date [%thread] %-5level %logger - %message%newline" />
          <subject value="%-5level %logger" />

          <to value="you@me.co.uk" />
          <from value="me@me.co.uk" />
          <smtpHost value="my-smtp-server" />
        </appender>

        <appender name="ColoredConsoleAppender" type="log4net.Appender.ColoredConsoleAppender">
          <layout type="log4net.Layout.PatternLayout" value="%date [%thread] %-5level %logger - %properties%newline" />
          <mapping>
            <level value="DEBUG" />
            <backColor value="Blue" />
            <foreColor value="White" />
          </mapping>
        </appender>

        <appender name="MessageObjectExpanderAppender" type="SampleAppendersApp.Appender.MessageObjectExpanderAppender, SampleAppendersApp">
          <appender-ref ref="ColoredConsoleAppender" />
        </appender>
        <appender name="AdoNetAppender_Access" type="log4net.Appender.AdoNetAppender">
          <bufferSize value="0" />
          <connectionString value="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\log\access.mdb;" />
          <commandText value="INSERT INTO Log ([Date],[Thread],[Level],[Logger],[Message]) VALUES (@log_date, @thread, @log_level, @logger, @message)" />
          <parameter>
            <parameterName value="@log_date" />
            <dbType value="String" />
            <size value="255" />
            <layout type="log4net.Layout.PatternLayout">
              <conversionPattern value="%date" />
            </layout>
          </parameter>
          <parameter>
            <parameterName value="@thread" />
            <dbType value="String" />
            <size value="255" />
            <layout type="log4net.Layout.PatternLayout">
              <conversionPattern value="%thread" />
            </layout>
          </parameter>
          <parameter>
            <parameterName value="@log_level" />
            <dbType value="String" />
            <size value="50" />
            <layout type="log4net.Layout.PatternLayout">
              <conversionPattern value="%level" />
            </layout>
          </parameter>
          <parameter>
            <parameterName value="@logger" />
            <dbType value="String" />
            <size value="255" />
            <layout type="log4net.Layout.PatternLayout">
              <conversionPattern value="%logger" />
            </layout>
          </parameter>
          <parameter>
            <parameterName value="@message" />
            <dbType value="String" />
            <size value="1024" />
            <layout type="log4net.Layout.PatternLayout">
              <conversionPattern value="%message" />
            </layout>
          </parameter>
        </appender>


        <!-- Setup the root category, add the appenders and set the default level -->
        <root>     
            <level value="ALL" />
            <appender-ref ref="ConsoleAppender" />   
          <!--<level value="ALL" />
          <appender-ref ref="MessageObjectExpanderAppender" />
          <appender-ref ref="ConsoleAppender" />
          <appender-ref ref="MessageBoxAppender" />
          <appender-ref ref="FireEventAppender" />
          <appender-ref ref="SimpleSmtpAppender" />-->
          <appender-ref ref="RollingFileAppender" />
          <appender-ref ref="AdoNetAppender_Access" />
        </root>

      </log4net>
     
    </configuration>

  • 相关阅读:
    TextBox类的成员
    【VB.Net】字节数与字符数的取得
    限制文本框的输入类型
    【转】FxCop 设计规则
    【Spread Sheet 应用(三)】Enter移向下一个单元格
    【ASP.NET】打开关闭新窗体
    常用字符对应ASCII码值
    初识CodeSmith分享两个模板
    【VB.NET】自定义控件(一)属性说明
    LeetCode: Length of Last Word
  • 原文地址:https://www.cnblogs.com/kingwangzhen/p/2111770.html
Copyright © 2020-2023  润新知