Configuration for NLog

When I am writing an application it is so important to make sure you record and log information correctly, there are a number of free loggers you can use

I have come to use NLog, by Jaroslaw Kowalski, it’s so easy to use and get up and running, which is what you really need if you are using a logger of any type.

But what is the best practice when using a log in a live environment?

Or more importantly what and how do you configure you configuration file to make sure you are logging all your information?

The way I see it is, capture your logging to the Event Log and a Database for information and tracing.

When it comes to Errors and Fatal logging then, write it to as many places as you can, an Error file, the Event Log, a Database Log, and perhaps a special Exception Database Log, because if something has failed, you’ll want to shout about it, and you want to record it in as many places as possible.

Here is an example of an NLog configuration

NLog.config (2.63 kb)

To setup the database use the following creation creation script

NLogDatabase.sql (1.16 kb)

Make sure within the SQL Database you have a user “nloguser”, with a password of “nlogpassword”, these are both defined in the NLog configuration file, and can be changed if need be.

That is it, all you have to do now is wait for your live application to log some information.

I am sure there are a few other configuration options available and I welcome anyones comments on how to improve this configuration file.

Finding if any records exist in a table

When you need to find if any records exist in a table or a selective snap shot of a table, you are prehaps like me in using the COUNT(*) SQL transaction and see if there are zero counts, but is this the most efficient method?

After a performance issue on one of my applications I found a new extension to LINQ to SQL called ANY(), from Ray Booysen on StackOverflow, here is an example of the SQL that is generated from LINQ:

The Results:

SELECT COUNT(*) AS [value] FROM [dbo].[Employees] AS [t0]




As you can see LINQ wins the day again.

TFS, SoureSafe or Subversion

Quite often when I start at a new client they ask me what are the benefits of TFS (Team Foundation Server), as they can not justify the cost, as it is very confusing (like may of Microsoft pricing structures)

I found this about “How much does Team Foundation Server REALLY cost vs SourceSafe?” by Eric Nelson, which is just what I have been looking for, as you can see the cost is not that much more than SourceSafe, and you gain huge benefits from TFS, as it is not just a Source Control, it’s much much more.