Reputation: 41
I am using Log4Net v1.2.13.0 with .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, e.g. Logger.IsDebugEnabled, Logger.IsInfoEnabled etc.
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.
Any ideas on what might be wrong?
Upvotes: 0
Views: 1499
Reputation: 73243
If LogManager.GetRepository().Configured
returns false, then log4net has not been initialised.
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. If it's in a separate file from the app.config, make sure that file is copied to the output.
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>()
.
It may help if you add your config to your question.
Upvotes: 3