zoukankan      html  css  js  c++  java
  • log4net日志输出配置即输出到文件又输出到visual studio的output窗口

    <configuration>
        <configSections>
            <section name="log4net" 
               type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
        </configSections>
        <log4net>
            <appender name="LogFileAppender" type="log4net.Appender.FileAppender">
                <param name="File" value="LogTest2.txt" />
                <param name="AppendToFile" value="true" />
                <layout type="log4net.Layout.PatternLayout">
                    <param name="Header" value="[Header]
    " />
                    <param name="Footer" value="[Footer]
    " />
                    <param name="ConversionPattern" value="%d [%t] %-5p %c %m%n" />
                </layout>
            </appender>
            
            <appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender" >
                <layout type="log4net.Layout.PatternLayout">
                    <param name="Header" value="[Header]
    " />
                    <param name="Footer" value="[Footer]
    " />
                    <param name="ConversionPattern" value="%d [%t] %-5p %c %m%n" />
                </layout>
            </appender>
    
            <root>
                <level value="INFO" />
                <appender-ref ref="LogFileAppender" />
                <appender-ref ref="ConsoleAppender" />
            </root>
        </log4net>
    </configuration>

    log类文件
    [assembly: log4net.Config.XmlConfigurator(ConfigFile="App.config",Watch = true)]
    namespace LogTest
    {
        public  class Logger
        {
            /// <summary>
            /// 输出日志到Log4Net
            /// </summary>
            /// <param name="t"></param>
            /// <param name="ex"></param>
            public static void WriteLog(Type t, Exception ex)
            {
                log4net.ILog log = log4net.LogManager.GetLogger(t);
                log.Error("Error", ex);
            }

            /// <summary>
            /// 输出日志到Log4Net
            /// </summary>
            /// <param name="t"></param>
            /// <param name="msg"></param>
            public static void WriteLog(Type t, string msg)
            {
                log4net.ILog log = log4net.LogManager.GetLogger(t);
                log.Error(msg);
            }

            public static void WriterInfoLog(Type t, string msg)
            {
                log4net.ILog log = log4net.LogManager.GetLogger(t);
                log.Info(msg);
            }
        }
    }
  • 相关阅读:
    js数组删除数组元素!收集
    ComponentArt MethodNeedDataSource etc.
    ComponentArt Grid Tips
    jira的附件位置如何查看
    有空来学习
    给你的windows设置博客园客户端,还等什么呢,赶快行动吧
    需要做的事
    那些事
    转帖:教你怎么偷懒
    买了电脑要做的几件事
  • 原文地址:https://www.cnblogs.com/tianmochou/p/6297330.html
Copyright © 2011-2022 走看看