I am having no luck getting NLog to work. Working through the tutorial, I have the exact code as seen there.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NLog;
namespace NLog2
{
class Program
{
static void Main(string[] args)
{
var c = new MyClass();
c.MyMethod1();
}
}
public class MyClass
{
private static Logger logger = LogManager.GetCurrentClassLogger();
public void MyMethod1()
{
logger.Trace("Sample trace message");
logger.Debug("Sample debug message");
logger.Info("Sample informational message");
logger.Warn("Sample warning message");
logger.Error("Sample error message");
logger.Fatal("Sample fatal error message");
// alternatively you can call the Log() method
// and pass log level as the parameter.
logger.Log(LogLevel.Info, "Sample fatal error message");
}
}
}
My config file (named NLog.config) looks like…
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<targets>
<target name="logfile" xsi:type="File" fileName="file.txt" />
</targets>
<rules>
<logger name="*" minlevel="Info" writeTo="logfile" />
</rules>
</nlog>
I get no output. Can someone see what the issue is here?
Dumb mistake. I had not set the config file to copy to the output directory.