Log4Net单独的配置文件不起作用 [英] Log4Net separate config file not working

查看:502
本文介绍了Log4Net单独的配置文件不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到一个奇怪的问题.我在一个解决方案中有多个项目.其中之一是WebAPI,它记录得很好.另一个是MVC管理站点,该站点不会登录.这是我尝试过的.

I'm having a strange problem. I have multiple projects in a solution. One of them is a WebAPI and it logs just fine. Another is an MVC admin site, this one won't log. Here's what I've tried.

我的登录代码:

var log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
log.Info("Some log message");  

在assemblyInfo中,我尝试了以下每个操作...

In the assemblyInfo I tried each of the following...

[assembly: log4net.Config.XmlConfigurator(ConfigFile = "logging.config", Watch = true)]
[assembly: log4net.Config.XmlConfigurator(ConfigFile = "C:\\full_path\\logging.config", Watch = true)]  

在Global.asax application_start中,我尝试了以下操作(删除了assemblyInfo行)

In the Global.asax application_start I've tried the following (removing the assemblyInfo lines)

log4net.Config.XmlConfigurator.ConfigureAndWatch(new FileInfo("Logging.config"));
var log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
log.Info("Application starting");  

这也不会创建日志.我可以创建的一种方法是使用global.asax中的代码以及logging.config的完整路径.

This also doesn't create a log. The one way I could get one created was to use the code in the global.asax and the full path to the logging.config.

我很困惑,因为webapi仅与只有相对路径的assemblyInfo一起使用.我还通过带有AssemblyInfo解决方案的MVC项目(相对路径)制作了一个示例虚拟解决方案,并且在这里也可以使用.

I'm confused, since the webapi works with just the assemblyInfo with only a relative path. I also made a sample dummy solution with an MVC project with the AssemblyInfo solution (relative path), and it worked there too.

有什么想法吗?

更新-发现问题

我必须在Application_Start中设置配置文件监视程序:

I had to setup the config file watcher in Application_Start:

log4net.Config.XmlConfigurator.ConfigureAndWatch(new System.IO.FileInfo(AppDomain.CurrentDomain.BaseDirectory + "logging.config"));

结果证明DotNetOpenAuth.Core.dll使用log4net,并且使使用AssemblyInfo解决方案无效.我在此博客中找到了详细信息: http://hanskindberg.wordpress.com/2013/04/07/log4net-configuration/

Turns out that DotNetOpenAuth.Core.dll uses log4net and will make using the AssemblyInfo solution not work. I found the details in this blog: http://hanskindberg.wordpress.com/2013/04/07/log4net-configuration/

谢谢

推荐答案

我必须在Application_Start中设置配置文件监视程序:

I had to setup the config file watcher in Application_Start:

log4net.Config.XmlConfigurator.ConfigureAndWatch(new System.IO.FileInfo(AppDomain.CurrentDomain.BaseDirectory + "logging.config"));

结果证明DotNetOpenAuth.Core.dll使用log4net,并且使使用AssemblyInfo解决方案无效.我在此博客中找到了详细信息: http://hanskindberg.wordpress.com/2013/04/07/log4net-configuration/(请参阅提及DotNetOpenAuth.Core.dll的段落)

Turns out that DotNetOpenAuth.Core.dll uses log4net and will make using the AssemblyInfo solution not work. I found the details in this blog: http://hanskindberg.wordpress.com/2013/04/07/log4net-configuration/ (look at the paragraph that mentions DotNetOpenAuth.Core.dll)

这篇关于Log4Net单独的配置文件不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆