• 深入学习common.logging


    若只需要使用log输出到控制台:

    .config配置如下:

      <configSections>
        <sectionGroup name="common">
          <!--1.此Adapter只输出到控制台-->
          <section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" />   
        </sectionGroup>
      </configSections>

     <common>
        <logging>      
          <!--1.此Adapter只输出到控制台-->
        <factoryAdapter type="Common.Logging.Simple.ConsoleOutLoggerFactoryAdapter, Common.Logging">
            <arg key="level" value="DEBUG" />
            <arg key="showLogName" value="true" />
            <arg key="showDataTime" value="true" />
            <arg key="dateTimeFormat" value="yyyy/MM/dd HH:mm:ss:fff" />
          </factoryAdapter>
        </logging>
      </common>

    二、使用common.logging.log4net adapter输出到log4net

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

      <configSections>
        <sectionGroup name="common">
          <!--1.此Adapter只输出到控制台-->
          <section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" />   
        </sectionGroup>
        <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
       
      </configSections>
      <common>
        <logging>
         
          <!--1.此Adapter只输出到控制台-->
          <!--<factoryAdapter type="Common.Logging.Simple.ConsoleOutLoggerFactoryAdapter, Common.Logging">
            <arg key="level" value="DEBUG" />
            <arg key="showLogName" value="true" />
            <arg key="showDataTime" value="true" />
            <arg key="dateTimeFormat" value="yyyy/MM/dd HH:mm:ss:fff" />
          </factoryAdapter>-->


          <factoryAdapter type="Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter, Common.Logging.Log4Net">
            <arg key="configType" value="INLINE" />
          </factoryAdapter>
         
        </logging>
      </common>

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

        <appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender, log4net">
          <param name="LockingModel" type="log4net.Appender.FileAppender+MinimalLock" />
          <param name="File" value="App_Data/log/" />
          <param name="StaticLogFileName" value="false" />
          <param name="DatePattern" value="yyyy-MM-dd.'log'" />
          <param name="AppendToFile" value="true" />
          <param name="MaxSizeRollBackups" value="10" />
          <param name="MaximumFileSize" value="5MB" />
          <param name="RollingStyle" value="Date" />
          <!--Size ==- Date-->
          <layout type="log4net.Layout.PatternLayout">
            <param name="ConversionPattern" value="%d [%t] %-5p %c - %m%n%newline" />
          </layout>
        </appender>
       
        <root>   <!--设置默认日志器-->
          <level value="DEBUG" />
          <appender-ref ref="RollingLogFileAppender" />
        </root>
       
        <logger name="MyApp.DataAccessLayer">
          <level value="DEBUG" />
        </logger>

        <logger name="RollingLogFileAppender">
          <level value="INFO"></level>
        </logger>    
      </log4net> 
    </configuration>

    测试logger项目

  • 相关阅读:
    内联函数和宏
    C++内联函数与宏定义
    C++函数声明和定义深度解析
    C++中的头文件和源文件
    国外程序员整理的 C++ 资源大全
    c语言中的字符数组与字符串
    iOS应用架构谈(二):View层的组织和调用方案(中)
    iOS应用架构谈(一):架构设计的方法论
    解决xib约束冲突
    tableView设置首尾
  • 原文地址:https://www.cnblogs.com/wucg/p/1806538.html
Copyright © 2020-2023  润新知