Navigation

Wednesday, May 05, 2010

How to trap Nlog events within your application

Being able to trap nLog log events within your application allows you to provide a default msg to your users without having to have the UI code everywhere in your application. 

This post describes how to setup nLog with an additional target that will fire an event in your application that you can then capture.

First there are a few changes to the log file;

image

Notice that we added a new target and rule for that target.  Next we need to add a class with a shared method to capture the event;

image

This allows you to catch the log event.

2 comments:

Anonymous said...

perfect! thanks for the info!

Anonymous said...

THANKS! I was having problems with NLog's email target xsi:target="Mail" (no errors in NLog's internal logger and no SMTP traffic in Wireshark :( ) so I just worked around using a method call!
Now everything works like a charm. Much obliged.