简体   繁体   中英

NLog can't write log file to disk

Good day, I am faced with problem. I try NLog, configuration code is listed below

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. I've tried @"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.

So, can anybody help me to understand what is wrong with @"D:\\" + filename .

PS Visual Studio 2013, runned with Administrator's rights. Also, I've tried ${basedir} . All was Ok.

Turn on the internal logging of 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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