Configure log4net logging in dll

后端 未结 1 486
走了就别回头了
走了就别回头了 2020-12-19 09:15

I\'m setting up a dll to be used as a third party dll for a different application. I want this dll to have it\'s own logging so the external application doesn\'t have to dea

相关标签:
1条回答
  • 2020-12-19 09:44

    You can configure log4net programmatically. Perhaps add this code to the constructor of your DLL.

    if (!log4net.LogManager.GetRepository().Configured)
    {
        // my DLL is referenced by web service applications to log SOAP requests before
        // execution is passed to the web method itself, so I load the log4net.config
        // file that resides in the web application root folder
        var configFileDirectory = (new DirectoryInfo(TraceExtension.AssemblyDirectory)).Parent; // not the bin folder but up one level
        var configFile = new FileInfo(configFileDirectory.FullName + "\\log4net.config");
    
        if (!configFile.Exists)
        {
            throw new FileLoadException(String.Format("The configuration file {0} does not exist", configFile));
        }
    
        log4net.Config.XmlConfigurator.Configure(configFile);
    }
    
    0 讨论(0)
提交回复
热议问题