Serilog 不会记录

问题描述 投票:0回答:1

我有以下代码:

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})");

没有创建日志文件。我做错了什么?

c# serilog serilog-sinks-file
1个回答
0
投票

获取 ProgramData 文件夹,然后创建您的路径:

var commonpath = GetFolderPath(SpecialFolder.CommonApplicationData);
var logFilePath = Path.Combine(commonpath, "LogFiles\\Platform\\Tool\\\"", "config_tool.log");
© www.soinside.com 2019 - 2024. All rights reserved.