• 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();
                }
            }
        }
    }
  • 相关阅读:
    Community Server(CS)是一个非常优秀的Asp.net开源软件
    乐在其中设计模式(C#)
    VSTO+WinForm+WebService+WCF+WPF示例
    系出名门 Android 系列文章索引
    DataTable 和List 相互转换
    C#异步TCP通讯类库FlyTcpFramework
    WCF+BizTalk开发系列
    精通MVC 3 框架
    我对架构的理解
    DataTable转换成IList
  • 原文地址:https://www.cnblogs.com/webglcn/p/2793179.html
Copyright © 2020-2023  润新知