Code Coverage by Clover.NET

LogManager.Configuration is null

View: New views
6 Messages — Rating Filter:   Alert me  

LogManager.Configuration is null

by Alex O. :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Everybody,

I am trying to use the memory target and therefore need to retrieve the target via LogManager.Configuration.FindTargetByName() first.

The problem is that LogManager.Configuration is always null, so it throws an exception. Is there an additional step to initialize the global configuration object?
My configuration is provided via NLog.config file where two targets are defined (file and memory) and has a couple of rules.

The project uses Windows CE 5.0, .NET CF 2.0 and VS2005.
Thanks for any advice.

Alex

Re: LogManager.Configuration is null

by Wob :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

Sorry I do have an answer but I have the same problem and can provide some more info. I too would like to hear answers to this.

What I've found is that if I have logging configured in a XML file then early in the app load the configuration is null. If I instantiate a new configuration it seems to stop the logging configured in the XML file. Well at least sometimes, I think it depends on where (how) the app is running.

I also have a memory target that is configured much later in the app load. It always has a non-null configuration.

Let me know if you find anything out. Replies on this forum are a bit hard to come by.

Rob Smyth

Re: LogManager.Configuration is null

by Alex O. :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

I have checked this property (LogManager.Configuration) in a regular console-based desktop application and it's not NULL, but in the .NET CF application this property is always NULL.
Appears that NLog for .NET CF lacks proper initialization somewhere or am I missing something?

Any ideas why it is so would be greatly appreciated.

Thank you,
Alex

Re: LogManager.Configuration is null

by Alex O. :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Never mind, I found my problem.

I have managed to step into the same trap twice!

In my VS2005 project the Build Action for NLog.config file was not set to Content, hence the file was not being deployed to the target device and that's why the configuration was missing.

Sorry for a silly post.

Re: LogManager.Configuration is null

by Wob :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Well I've seen it both null and not null in a Windows XP .Net 2.0 application.

Rob Smyth

Re: LogManager.Configuration is null

by Jaroslaw_Kowalski :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Exactly. Note that for CF applications you may have to copy NLog.config manually to the device - sometimes VS doesn't do it automatically.
LightInTheBox - Buy quality products at wholesale price