I have a serilog code and I want to move the configuration to the web.config file.
everything works fine but the problem is with the path of the file:
var logFileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, $"EnBW.DokumentErfassung.Web-{Environment.MachineName}.log");
Log.Logger = new LoggerConfiguration()
.ReadFrom.AppSettings();
I want to write the new file in the same server path, the web.config code is:
<add key="serilog:using:RollingFile" value="Serilog.Sinks.RollingFile" />
<add key="serilog:write-to:RollingFile.pathFormat" value="log123-{Date}.txt" />
but the files saved has been saved in C:/program file/ .....
I want it to be saved in the same Domain path. what should I do?
The app settings provider supports environment variables, so in Global.asax.cs before configuring the logger:
Environment.SetEnvironmentVariable("BASEDIR", AppDomain.CurrentDomain.BaseDirectory);
And use %BASEDIR%
in config:
<add key="serilog:write-to:RollingFile.pathFormat"
value="%BASEDIR%\logs\log-{Date}.txt" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With