zoukankan      html  css  js  c++  java
  • log4net basic example write to file

    <?xml version="1.0"?>
    <configuration>
      <configSections>
        <section name="SubSonicService" type="SubSonic.SubSonicSection, SubSonic" requirePermission="false"/>
        <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net"/>
      </configSections>
    
      <log4net>
        <logger name="loginfo">
          <level value="ALL"/>
          <appender-ref ref="InfoAppender"/>
        </logger>
        
        <appender name="InfoAppender" type="log4net.Appender.RollingFileAppender">
          <param name="File" value="Log\\test.log"/>
          <param name="AppendToFile" value="false"/>
          <param name="MaximumFileSize" value="1KB"/>
          <param name="MaxSizeRollBackups" value="100"/>
          <param name="DatePattern" value="yyyy-MM-dd"/>
          <param name="RollingStyle" value="Date"/>
          <layout type="log4net.Layout.PatternLayout">
            <param name="ConversionPattern" value="%d [%t] %-5p %c - %m%n" />
          </layout>
        </appender>
    
        <!-- Set root logger level to DEBUG and its only appender to A1 --><!--
        <root>
          <level value="ALL"/>
          <appender-ref ref="InfoAppender"/>
        </root>-->
      </log4net>
    <startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>
    using log4net;
    using log4net.Config;
    
    namespace TestLog4Net
    {
        class Program
        {
            static readonly ILog logger = LogManager.GetLogger("loginfo");
            static void Main(string[] args)
            {
                try
                {
                    log4net.Config.XmlConfigurator.Configure();
                    logger.Debug("Here is a debug log.");
                    logger.Info("... and an Info log.");
                    logger.Warn("... and a warning.");
                    logger.Error("... and an error.");
                    logger.Fatal("... and a fatal error.");
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                    Console.ReadLine();
                }
            }
        }
    }
  • 相关阅读:
    利用JNI技术在Android中调用、调试C++代码
    iOS在线更新framework,使用NSBundle动态读取
    CocoaPods pod install
    Quartz 2D在ios中的使用简述二:创建画布
    iOS并发编程笔记【转】
    openCV C++ 代码笔记
    Quartz 2D在ios中的使用简述一:坐标体系
    ios视频播放器,代码和界面分离
    mac显示和隐藏文件
    3点画圆
  • 原文地址:https://www.cnblogs.com/webglcn/p/2793179.html
Copyright © 2011-2022 走看看