Log4Net and GAC - How to reference Configuration Files?

前端 未结 2 648
日久生厌
日久生厌 2021-01-28 03:06

I am using log4net during my development, as as part of a project constraint, I now need to add it to the Global Assembly Cache.

The logging definitions are in a file Lo

2条回答
  •  北恋
    北恋 (楼主)
    2021-01-28 04:00

    You might ensure that your log4net.xml file is set to "Copy Always" (Right Click on log4net.xml -> Properties -> Copy to Output Directory = Copy always). To ensure that your config file is being copied, you should check your bin\debug or bin\release directory and verify that the log4net.xml file exists in the same directory that your application executes.

    If that doesn't workthen you can try enabling internal debugging in log4net. To enable internal debugging, add the following key to your app.config file. This will send internal log4net debug messages to your Visual Studio Output window (View -> Output).

    
      
        
      
    
    

    For more information on log4net's internal debugging, you might check Phil Haack's blog post here.

    If all else fails, you can turn on internal debugging and explicitly load the configuration by calling log4net's XmlConfigurator.ConfigureAndWatch method.

    var fi = new FileInfo(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\log4net.xml");
    XmlConfigurator.ConfigureAndWatch(fi);
    

提交回复
热议问题