|
using System;
using System.Globalization;
using NLog;
class MyClass {
static Logger logger = LogManager.GetLogger("MyClass");
static void Main()
{
// you can use an interface known from log4net
logger.Trace("This is a trace message");
logger.Debug("This is a debugging message");
logger.Info("This is a information message");
logger.Warn("This is a warning message");
logger.Error("This is an error");
logger.Fatal("This is a fatal error message");
// you can ask if the logging is enabled before writing
if (logger.IsDebugEnabled) {
logger.Debug("Some debug info");
}
// you can use WriteLine() style formatting
logger.Debug("The result is {0} {1}", 1 + 2, "zzz");
// you can even pass IFormatProvider for maximum flexibility
logger.Debug(CultureInfo.InvariantCulture,
"The current time is {0}", DateTime.Now);
// you can ask if the logging is enabled for specified level
if (logger.IsEnabled(LogLevel.Warn)) {
// and you can write the message for a particular level, too
logger.Log(LogLevel.Warn, "Some warning info");
}
}
}
|
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.