简体   繁体   English

NLog无法将日志文件写入磁盘

[英]NLog can't write log file to disk

Good day, I am faced with problem. 美好的一天,我遇到了问题。 I try NLog, configuration code is listed below 我尝试使用NLog,配置代码如下

var config = new LoggingConfiguration();

var fileTarget = new FileTarget();
config.AddTarget("file", fileTarget);

fileTarget.FileName = @"D:\" + filename;
fileTarget.Layout = @"${date:format=HH\:mm\:ss} ${logger} ${message}";

var rule1 = new LoggingRule("*", LogLevel.Debug, fileTarget);
config.LoggingRules.Add(rule1);

LogManager.Configuration = config;

Logger logger = LogManager.GetLogger("Example");
logger.Debug("debug log message");

Code was taken from some tutorial. 代码摘自一些教程。 And nothing happened. 没有任何反应。 Log file was not created on disk D. But it was created in project's output directory. 日志文件不是在磁盘D上创建的。但是它是在项目的输出目录中创建的。 I've tried @"C:\\" + filename . 我试过@"C:\\" + filename I was surprised, but log file was there. 我很惊讶,但是日志文件在那里。

Then I've tried to log to @"D:\\SomeFolder\\" + filename and file also was there. 然后,我尝试登录到@"D:\\SomeFolder\\" + filename和文件。

So, can anybody help me to understand what is wrong with @"D:\\" + filename . 因此,有人可以帮助我了解@"D:\\" + filename怎么了。

PS Visual Studio 2013, runned with Administrator's rights. PS Visual Studio 2013,具有管理员权限。 Also, I've tried ${basedir} . 另外,我尝试了${basedir} All was Ok. 一切都还好。

Turn on the internal logging of NLog. 打开NLog的内部日志记录。 Check what you have there. 检查那里有什么。 Also instead of writing the internal log to file write it to console. 另外,不要将内部日志写入文件,而是将其写入控制台。

 // enable internal logging to the console
    InternalLogger.LogToConsole = true;

Look for errors in the internal logs. 在内部日志中查找错误。 You'll get the idea why it's not working. 您将了解为什么它不起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM