Serilog won't log

77 views Asked by At

I have the following code:

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

There is no log file created. What am I doing wrong?

1

There are 1 answers

0
FortyTwo On BEST ANSWER

Get ProgramData folder and then create your path:

var commonpath = GetFolderPath(SpecialFolder.CommonApplicationData);
var logFilePath = Path.Combine(commonpath, "LogFiles\\Platform\\Tool\\config_tool.log");