我有以下代码:
var logFilePath = Path.Combine("\"%ProgramData%\\LogFiles\\Platform\\Tool\\\"", "config_tool.log");
// Default logging: Windows event log + console
var defaultLoggerConfig = new LoggerConfiguration()
.WriteTo.EventLog("Configuration Tool", manageEventSource: true)
.WriteTo.Console(LogEventLevel.Information, outputTemplate: "{Message:lj}{NewLine}{Exception}")
.WriteTo.File(path: logFilePath, LogEventLevel.Information, encoding: Encoding.UTF8, outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zz} [{Level:u3}] {Message}{NewLine}{Exception}");
Log.Logger = defaultLoggerConfig.CreateLogger();
Log.Logger.Write(LogEventLevel.Information, $"{Constants.Common.AppName} ({AppVersion})");
没有创建日志文件。我做错了什么?
获取 ProgramData 文件夹,然后创建您的路径:
var commonpath = GetFolderPath(SpecialFolder.CommonApplicationData);
var logFilePath = Path.Combine(commonpath, "LogFiles\\Platform\\Tool\\\"", "config_tool.log");