• How to track down log4net problems


    How to track down log4net problems

    First you have to set this value on the application configuration file:

    <configuration>
       <appSettings>
          <add key="log4net.Internal.Debug" value="true"/>
       </appSettings>
    </configuration>

    Then, to determine the file in which you want to save the output you can add the following code in the same .config file:

    <configuration>
    ...
    
    <system.diagnostics>
        <trace autoflush="true">
            <listeners>
                <add 
                    name="textWriterTraceListener" 
                    type="System.Diagnostics.TextWriterTraceListener" 
                    initializeData="C:	mplog4net.txt" />
            </listeners>
        </trace>
    </system.diagnostics>
    
    ...
    </configuration>

    You can find a more detailed explanation under 'How do I enable log4net internal debugging?' in the log4net FAQ page.

    How do I enable log4net internal debugging?

    There are 2 different ways to enable internal debugging in log4net. These are listed below. The preferred method is to specify the log4net.Internal.Debug option in the application's config file.

    • Internal debugging can also be enabled by setting a value in the application's configuration file (not the log4net configuration file, unless the log4net config data is embedded in the application's config file). The log4net.Internal.Debug application setting must be set to the value true. For example:

      <?xml version="1.0" encoding="utf-8" ?>
      <configuration>
          <appSettings>
              <add key="log4net.Internal.Debug" value="true"/>
          </appSettings>
      </configuration>

      This setting is read immediately on startup an will cause all internal debugging messages to be emitted.

    • To enable log4net's internal debug programmatically you need to set the log4net.Util.LogLog.InternalDebugging property to true. Obviously the sooner this is set the more debug will be produced.

    Internal debugging messages are written to the console and to the System.Diagnostics.Trace system. If the application does not have a console the messages logged there will be lost. Note that an application can redirect the console stream by setting the System.Console.Out. The Trace system will by default send the message to an attached debugger (where the messages will appear in the output window). If the process does not have a debugger attached then the messages are sent to the system debugger. A utility like DebugView from http://www.sysinternals.com may be used to capture these messages.

    As log4net internal debug messages are written to the System.Diagnostics.Trace system it is possible to redirect those messages to a local file. You can define a trace listener by adding the following to your application's .config file:

    <configuration>
        ...
        
        <system.diagnostics>
            <trace autoflush="true">
                <listeners>
                    <add 
                        name="textWriterTraceListener" 
                        type="System.Diagnostics.TextWriterTraceListener" 
                        initializeData="C:	mplog4net.txt" />
                </listeners>
            </trace>
        </system.diagnostics>
    
        ...
    </configuration>

    Make sure that the process running your application has permission to write to this file.

  • 相关阅读:
    判断是否微信浏览器,是的话,加入自己想加的功能
    Spring MVC源码(三) ----- @RequestBody和@ResponseBody原理解析
    Spring MVC源码(二) ----- DispatcherServlet 请求处理流程 面试必问
    Spring MVC源码(一) ----- 启动过程与组件初始化
    spring5 源码深度解析----- IOC 之 bean 的初始化
    spring5 源码深度解析-----IOC 之 循环依赖处理
    spring5 源码深度解析-----IOC 之 属性填充
    spring5 源码深度解析----- IOC 之 bean 创建
    spring5 源码深度解析----- IOC 之 开启 bean 的加载
    spring5 源码深度解析----- IOC 之 自定义标签解析
  • 原文地址:https://www.cnblogs.com/chucklu/p/13381646.html
Copyright © 2020-2023  润新知