Tôi đang cố gắng thêm ghi nhật ký vào ứng dụng đang chạy trên thiết bị di động với Windows Mobile 6.1. .NET Compact framework 3.5. sử dụng NLog.NLog không tạo tệp nhật ký
Tôi đã cài đặt phiên bản phân phối NLog thích hợp.
Tuy nhiên, không có tệp nhật ký nào được tạo.
Đây là tệp NLog.config
của tôi.
<?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=".\Neolant.ASRM.Terminal.log" layout="${longdate}|${level}|${message}|${exception}" autoFlush="true"/>
</targets>
<rules>
<logger name="*" minlevel="Info" writeTo="logfile" />
</rules>
</nlog>
Đây là mã thử nghiệm tôi đang sử dụng.
public static void Main()
{
try
{
AppDomain.CurrentDomain.UnhandledException += CurrentDomainOnUnhandledException;
var logger = NLog.LogManager.GetLogger("UpperLevel");
logger.Info("test test test.");
try
{
throw new Exception("Unexpected!");
}
catch (Exception e)
{
var logger = NLog.LogManager.GetLogger("UpperLevel");
logger.WarnException("An exception occured.", e);
}
throw new Exception("Suddenly!");
}
finally
{
NLog.LogManager.Flush();
}
}
private static void CurrentDomainOnUnhandledException(object sender, UnhandledExceptionEventArgs unhandledExceptionEventArgs)
{
var logger = NLog.LogManager.GetLogger("UpperLevel");
logger.FatalException("Application closed due to exception.", unhandledExceptionEventArgs.ExceptionObject as Exception);
NLog.LogManager.Flush();
}
Bạn đã thử nghiệm với tên file/đường dẫn khác nhau? Ví dụ: 'fileName =" Neolant.ASRM.Terminal.log "' without '. \\'? Nlog.Config nằm trong thư mục ứng dụng? Ngoài ra, bạn có thể bật [Ghi nhật ký nội bộ của Nlog] (http://nlog-project.org/wiki/Logging_is_not_working_-_how_to_troubleshoot_it%3F) để nhận thêm thông tin về sự cố của bạn. – nemesv
Tôi đã thử tên tệp có và không có '. \' Với kết quả tương tự (có nghĩa là, không có). NLog.config được triển khai vào thư mục ứng dụng. Sẽ thử đăng nhập nội bộ ngay bây giờ. – Srv19
Theo liên kết bạn đã cung cấp, tôi đã tìm hiểu giải pháp. Cảm ơn rất nhiều. – Srv19