我没有运气让NLog工作。通过tutorial的工作,我看到了那里的确切代码。不能让NLog工作
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");
}
}
}
我的配置文件(名为NLog.config)看起来像......
<?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>
我没有得到任何输出。有人可以看到这个问题在这里吗?
在'nlog'元素上设置'throwExceptions =“true”'和'internalLogFile =“nlog.txt”internalLogLevel =“Trace”'。也许你会在内部的日志文件中看到一些东西......是在bin目录中的'NLog.config'吗? – nemesv 2012-03-28 20:46:13