serilog / serilog-settings-configuration

A Serilog configuration provider that reads from Microsoft.Extensions.Configuration
Apache License 2.0
444 stars 129 forks source link

Enviroment variables not works in appsettings #384

Closed pampua84 closed 1 year ago

pampua84 commented 1 year ago

Hi, I'm trying to use an environment variable in the appsettings.json to set the base path ("BASEDIR") for writing logs like below:

{ "Name": "File", "Args": { "path": "%BASEDIR%/logs/All/log-.log", "outputTemplate": "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj} <s1:{SourceContext}> {RequestId}{NewLine}{Exception}", "rollingInterval": "Day", "retainedFileCountLimit": "7", "buffered": false, "levelSwitch": "$fileSwitch" }

and in code:

Environment.SetEnvironmentVariable("BASEDIR", AppDomain.CurrentDomain.BaseDirectory);

upgrading the package to the latest version this thing seems to no longer work, while everything worked fine before, in fact while before I had the logs folder in the bin\Debug\net7.0 folder, now the %BASEDIR% folder appears in the main project folder.

image

sungam3r commented 1 year ago

Hi, @pampua84 . A minimum repro is appreciated.

pampua84 commented 1 year ago

Hi, @sungam3r I don't understand what you mean. Could you explain better please?

sungam3r commented 1 year ago

I mean posting either unit test or other runnable code to demonstrate an issue.

pampua84 commented 1 year ago

I updated the Serilog package and the problem no longer occurs