Adding default rules and targets

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Adding default rules and targets

davemoor
Hi

I'd like to use NLog in my app for general logging.  But I want to 'Hard Code' a specific target and rule to log messages from my data load routines to a specific database table.

Can I programatically add rules and targets once the logger has been created?

The one issue with this that I can see is if autoReload="true" gets set in the config file I guess my hardcoded config will be removed if the config file is changed.

The other way I can think to do this is to have a seperate data load logger and main logger, so could I create a target in the data load logger of the main logger so any warnings or errors in the load process are logged by both?

I'm new to NLog so the above might be total garbage.

Thanks

Dave
Reply | Threaded
Open this post in threaded view
|

Re: Adding default rules and targets

Jarek Kowalski
Administrator
The loggers are independent from their configuration. If you create a logger and the configuration file changes the changes are propagated to all "alive" loggers.

There are some options for you:

1. Use include files:

<nlog>
    <include file="hardcoded.xml" />

    ... other rules and targets go here
</nlog>

2. Another solution for you might be a separate LogFactory instance (only added few days ago) and described in this thread:

http://www.nabble.com/newbie-usage-question-tf1952903s6167.html

Loggers created through this logfactory will be independent from the ordinary ones and thus you'll be able to reload the "general" configuration while preventing the "hardcoded"  from reloading.

Jarek
NLog Blog