Jarek Kowalski published Nlog 2.0 RC with some great additions.
http://jkowalski.com/2011/06/18/nlog-2-0-release-candidate-is-out/
.Net Developer, Blogger, VP Development EIS, Public Safety Software (Police, Fire, EMS, Jail)
Jarek Kowalski published Nlog 2.0 RC with some great additions.
http://jkowalski.com/2011/06/18/nlog-2-0-release-candidate-is-out/
I just completed a windows mobile client application targeting a 5.1 mobile OS. This project provided the ability to scan a barcode with the embedded barcode scanner, return the selected item from a web service (along with a photo stored on a network share) and allow the user to post movement and status changed on the scanned item.
This was the first time I used NLog on a Compact Framework device and after getting use to some of the minor issues related to the OS was able to use NLog just like a VB.net application.
In this project I configured Nlog via code rather then a configuration file. The first issue was getting the application path to pass to Nlog.
First, I created a global variable to save the path and the Nlog logger;
Public gApplicationPath As String = String.Empty
Public gLogger As NLog.Logger = Nothing
Next I set the path with the following statement;
gApplicationPath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase)
The configuration was simple with the following code;
NLog.Internal.InternalLogger.LogFile = gApplicationPath & "\nlog.txt"
NLog.LogManager.ThrowExceptions = FalseDim config As New NLog.Config.LoggingConfiguration
Dim filetarget As New NLog.Targets.FileTarget
With filetarget
.Name = "filetarget"
.FileName = gApplicationPath & "\ErrorLog.txt"
.Layout = "${longdate}||${level}||${logger}|||${message}|${exception:format=message:separator=*}^"
End With
config.AddTarget("file", filetarget)
Dim rule1 As New NLog.Config.LoggingRule("*", NLog.LogLevel.Trace, filetarget)
config.LoggingRules.Add(rule1)
NLog.LogManager.Configuration = config
gLogger = LogManager.GetLogger("myLogerName")
Pretty straightforward!
I am a big fan of targeting a database to store the logging data to and will address updating the application to use that target next time.
I have been using Nlog for a number of years and find it to be a great logging component. Today my post on loadFromRemoteSources which deals with referencing assemblies from remote network shares in VS2010 was re-tweeted by Jarek on his twitter page!
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;
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;
This allows you to catch the log event.