Customising NLog's Logger class

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

Customising NLog's Logger class

Jonathan Parker
Hi,

I'm looking at customising NLog.

Basically I need to be able to pass in a predefined error code with the error message.
The logger should then look up the severity in a file and determine from that what should be called in NLog (Info, Error, Fatal etc).
Our clients will then be able to look at the file to find the description that matches the error code.

I've found it difficult so far to extend Logger via inheritance (no public constructor on Logger).

Is composition the general way?

Any help will be greatly appreciated.

Thanks,

Jonathan.

------------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It is the best place to buy or sell services for
just about anything Open Source.
http://p.sf.net/sfu/Xq1LFB
_______________________________________________
Nlog-list mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/nlog-list
Reply | Threaded
Open this post in threaded view
|

Re: Customising NLog's Logger class

Jarek Kowalski
Administrator
The constructor on Logger is protected which is perfectly fine for inheritance. Your derived class just has to have a public constructor.
There's actually an example in:
 
 
It demonstrates how to extend a logger. Note that in order to create loggers of your particular type, you need to call special overloads of LogManager.Get*Logger().
Alternatively you can use generic LogFactory<YourLoggerType> - see the source code in LogFactory.cs
 
Jarek
 
----- Original Message -----
Sent: Thursday, January 08, 2009 11:02 PM
Subject: [Nlog-list] Customising NLog's Logger class

Hi,

I'm looking at customising NLog.

Basically I need to be able to pass in a predefined error code with the error message.
The logger should then look up the severity in a file and determine from that what should be called in NLog (Info, Error, Fatal etc).
Our clients will then be able to look at the file to find the description that matches the error code.

I've found it difficult so far to extend Logger via inheritance (no public constructor on Logger).

Is composition the general way?

Any help will be greatly appreciated.

Thanks,

Jonathan.


------------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It is the best place to buy or sell services for
just about anything Open Source.
http://p.sf.net/sfu/Xq1LFB


_______________________________________________
Nlog-list mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/nlog-list

------------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It is the best place to buy or sell services for
just about anything Open Source.
http://p.sf.net/sfu/Xq1LFB
_______________________________________________
Nlog-list mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/nlog-list
NLog Blog