• 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();
                }
            }
        }
    }
  • 相关阅读:
    centos 7.0 yum 分开安装 LAMP 环境 +zabbix3.4环境
    互联网产品接入支付功能如何测试?
    python实现:将文本文件分割成多个小文本文件(php也可实现)
    『危机领导力』告诉我们如何带好团队
    Fiddler显示服务器IP的方法
    Google PageSpeed Tools 性能测试分析
    写给浮躁的测试工程师一封信
    数据库事务和锁
    测试工作中ADB命令实战
    git使用基础
  • 原文地址:https://www.cnblogs.com/webglcn/p/2793179.html
Copyright © 2020-2023  润新知