../_images/sitetitle2.png

Getting Started (Quick Start)

If you are totally new to logging in software, first read Introduction to Logging.

If you are new to tag-based logging, read Introduction to Tag-Based Logging.

Step 1: Install Using NuGet

NuLog is delivered using NuGet. Look for, and install the NuLog package into any project you wish to use NuLog for. NuLog supports .Net versions 3.5, 4 and 4.5.2 (and on).

You’ll want to get your configuration squared away. For more information on configuring NuLog, head over to Configuration Template.


Step 2: Get Standard Logger

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
// use NuLog
using NuLog;

namespace NuLogSnippets.Docs
{
    public class GetStandardLogger
    {
        // Get the logger from the log manager
        private static readonly ILogger _logger = LogManager.GetLogger();
        }
    }

Step 3: Log

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
using NuLog;

namespace NuLogSnippets.Docs
{
    public class GetStandardLogger
    {
        private static readonly ILogger _logger = LogManager.GetLogger();

        public void DoSomething()
        {
            // Log something
            _logger.Log("Hello, world!  I'll be dispatched later.");
            _logger.LogNow("Hello, world! I'll be dispatched immediately.");
        }
    }
}

Log vs. LogNow

NuLog is designed to defer the actual action of dispatching and logging a log event to a queue that is managed by a background process (thread). This allows control to return to the logging method much sooner, instead of having to wait for the log message to be dispatched before returning. When calling Log on the Logger, the log event is generated by the Logger, then added to a queue for dispatch by a background process. To dispatch a log event for immediate logging, use LogNow instead.

It is highly suggested that you use Log for almost everything, only using LogNow for log events that are more critically recorded.

The Finalizer on the class that dispatches the log events has been overridden to ensure that no new log events are queued, and any existing log events in the queue are dispatched, before the dispatcher is disposed. This means that there is a higher degree of certainty that queued log events are dispatched before the program exits. The only time queued log events won’t be dispatched, is in case of a total crash of the application, or power failure - which would likely cause log event failure, anyways. If the nature of the log event is such that failure cannot be risked, just use LogNow for the event instead.