In code …

It’s really easy to add logging to any application that uses our .net network library. Under the hood we are using NLog and it can be enabled as follows:

If you just want to log to a console window add this C# code snippet wherever you are also enabling the library:

Note: These code snippets will require the following namespace references:

If you also want to log to the console and a text file (log.txt) then use this C# code snippet instead:

You can also add entries to the log from anywhere in your own code as follows:

If you want to disable logging at any point use:

Using an external logging configuration …

It is also possible to specify the logging configuration in an external file. An external logging configuration file may look as follows, named nlog.config, for more information please see here:

In your own code, should this file exist you can enable logging using it’s contents as follows:

The advantage of this syntax is that you don’t need to rebuild your code should your logging requirements change.