Click here to Skip to main content
15,892,059 members
Articles / Programming Languages / C#

Logging with NLog

Rate me:
Please Sign up or sign in to vote.
1.68/5 (13 votes)
6 Jan 20073 min read 52.3K   69   20  
The article describes how to configure nlog to log reports as per your requirement
<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="style.xsl" ?>
<content lang="en" id="documentation" subid="howto">
    <h1>How to troubleshoot logging problems</h1>
    <p>If you have trouble getting NLog to work properly you may want to enable some debugging
        output to see what may be going wrong. This document describes the available internal debugging 
        features of NLog.</p>
    <h4>Enabling internal logging</h4>
    The following variables can be used to control NLog internal debugging:
    <p><code>NLOG_INTERNAL_LOG_TO_CONSOLE</code> - if this variable is found in the environment 
        NLog outputs internal logging information to the console using <code>Console.WriteLine</code>.</p>
    <p><code>NLOG_INTERNAL_LOG_FILE</code> - if this variable is found in the environment 
        NLog outputs internal logging information to the specified file. The file must be writable
        by the current user or it will not be created.</p>
    <p><code>NLOG_INTERNAL_LOG_LEVEL</code> - sets the internal logging level. The available values
        are <code>Debug, Info, Warn, Error, Fatal</code> - the default is <code>Info</code> which should
        be appropriate for most cases, to get more detailed logging - set it to <code>Debug</code>.</p>
    <h4>Enabling internal logging using the environment variables</h4>
    There are two cases here - setting the variables for an interactive process or for a service process.
    <h5>Enabling internal logging in the interactive processes</h5>
    <p>This case is easy. Just open the command prompt (<code>cmd.exe</code>), set your variables using
        the SET command and run your program. Here's the example:
    </p>
    <pre style="background-color: black; color: yellow; font-family: Courier New;padding: 10px; width: 80%">
        Microsoft Windows [Version 5.2.3790]
        (C) Copyright 1985-2003 Microsoft Corp.

        C:\MyApp&gt;set NLOG_INTERNAL_LOG_FILE=c:\temp\mylog.txt

        C:\MyApp&gt;set NLOG_INTERNAL_LOG_LEVEL=Debug

        C:\MyApp&gt;myapp.exe
    </pre>
    <h5>Enabling internal logging in the service processes</h5>
    <p>TO BE WRITTEN</p>

    <h4>Enabling internal logging programmatically</h4>
    <p>TO BE WRITTEN</p>
</content>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions