|
<pre xml:space='preserve'><span class='csharp'><span class='k'>using</span> System;
<span class='k'>using</span> System.Globalization;
<span class='k'>using</span> NLog;
<span class='k'>class</span> MyClass {
<span class='k'>static</span> Logger logger = LogManager.GetLogger(<span class='s'>"MyClass"</span>);
<span class='k'>static</span> <span class='k'>void</span> Main()
{
<span class='c'>// you can use an interface known from log4net</span>
logger.Debug(<span class='s'>"This is a debugging message"</span>);
logger.Info(<span class='s'>"This is a information message"</span>);
logger.Warn(<span class='s'>"This is a warning message"</span>);
logger.Error(<span class='s'>"This is an error"</span>);
logger.Fatal(<span class='s'>"This is a fatal error message"</span>);
<span class='c'>// you can ask if the logging is enabled before writing</span>
<span class='k'>if</span> (logger.IsDebugEnabled) {
logger.Debug(<span class='s'>"Some debug info"</span>);
}
<span class='c'>// you can use WriteLine() style formatting</span>
logger.Debug(<span class='s'>"The result is {0} {1}"</span>, 1 + 2, <span class='s'>"zzz"</span>);
<span class='c'>// you can even pass IFormatProvider for maximum flexibility</span>
logger.Debug(CultureInfo.InvariantCulture,
<span class='s'>"The current time is {0}"</span>, DateTime.Now);
<span class='c'>// you can ask if the logging is enabled for specified level</span>
<span class='k'>if</span> (logger.IsEnabled(LogLevel.Warn)) {
<span class='c'>// and you can write the message for a particular level, too</span>
logger.Log(LogLevel.Warn, <span class='s'>"Some warning info"</span>);
}
}
}
</span>
</pre>
|
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.
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
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.