一些奇怪的原因n日志不显示任何东西,当我写到控制台,在Program.cs中Main()方法我分配nlog.config:NLog不显示任何内容?
LogManager.Configuration = new XmlLoggingConfiguration("assets/packages/nlog/nlog.config");
这里是配置:
<nlog throwExceptions="true">
<targets>
<target name="file" type="File" fileName="${basedir}/assets/logging/log.txt" />
</targets>
<rules>
<logger name="*" minLevel="Info" writeTo="File" />
</rules>
</nlog>
下面是一个简单类:
private static readonly ILogger Logger = LogManager.GetCurrentClassLogger();
public MyClass()
{
Console.Write("lol");
Logger.Debug("Debug test...");
Logger.Error("Debug test...");
Logger.Fatal("Debug test...");
Logger.Info("Debug test...");
Logger.Trace("Debug test...");
Logger.Warn("Debug test...");
}
我知道正在调用的方法,因为我得到的“笑”,只是没有实际在控制台上的日志,但它确实写到/assets/logging/log.txt文件。
你确认你的文件名的路径是正确的:
从log.txt的输出? –
是的,如果不是,它会抛出异常。 – Ashkru
请检查https://github.com/NLog/NLog/wiki/Internal-logging – Julian