由于某些奇怪的原因,当我在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...");
}
我知道这个方法被调用了,因为我得到了“lol”,但控制台上实际的日志没有打印出来,但它确实写入了 /assets/logging/log.txt 文件。