简体   繁体   English

Windows服务未使用Log4Net记录

[英]Windows service not logging with Log4Net

I am using Log4Net v1.2.13.0 with .Net 4.5. 我正在将Log4Net v1.2.13.0与.Net 4.5一起使用。 It is logging just fine when I run my code as a console application. 当我将代码作为控制台应用程序运行时,日志记录很好。 However, when I run it as a service I get nothing. 但是,当我将其作为服务运行时,我一无所获。 The service is running as my login with admin permissions. 该服务作为具有管理员权限的登录名运行。 When I attach to the process and step through the code in debug mode it is as if nothing in the config file has even been read. 当我附加到该过程并在调试模式下逐步执行代码时,就好像配置文件中的任何内容都没有被读取。 When you check the logger object none of the properties are set true, eg Logger.IsDebugEnabled, Logger.IsInfoEnabled etc. 当您检查记录器对象时,所有属性均未设置为true,例如Logger.IsDebugEnabled,Logger.IsInfoEnabled等。

Here is how I am configuring a logger instance and then retrieving the same instance. 这是我配置记录器实例,然后检索相同实例的方式。

private static readonly ILog Logger = LogManager.GetLogger(typeof(ServiceHostService));

I am setting the logging level to ALL. 我将日志记录级别设置为ALL。

Any ideas on what might be wrong? 有什么想法可能有问题吗?

If LogManager.GetRepository().Configured returns false, then log4net has not been initialised. 如果LogManager.GetRepository().Configured返回false,则说明log4net尚未初始化。

Assuming you have your config in XML, will need either a call to log4net.Config.XmlConfigurator.Configure(…) or an assembly attribute like [assembly: log4net.Config.XmlConfigurator(…)] to load the config. 假设您使用XML进行配置,则需要调用log4net.Config.XmlConfigurator.Configure(…)或诸如[assembly: log4net.Config.XmlConfigurator(…)]类的程序集属性来加载配置。 If it's in a separate file from the app.config, make sure that file is copied to the output. 如果它与app.config位于单独的文件中,请确保将该文件复制到输出中。

If log4net is configured but all log levels are still disabled, check for configuration issues by looking at the results of LogManager.GetRepository().ConfigurationMessages.Cast<LogLog>() . 如果已配置log4net,但仍禁用了所有日志级别,请通过查看LogManager.GetRepository().ConfigurationMessages.Cast<LogLog>()的结果来检查配置问题。

It may help if you add your config to your question. 如果将配置添加到您的问题中可能会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM