1

I started my new project in ASP.NET Core and I have a question.

I have 2 loggers: a) nLog, that have it's config in nlog.config file b) serilog, that have it's config in appsettings.json

At this moment, I have 2 locations to store logs: fileName="${basedir}/logs/EPR/nlog-all-${shortdate}.log - nLog "SerilogFile": "logs/serilog-{Date}.txt" - serilog

My question is, how to get basedir catalog in appsettings.json file.

1
  • Did you solve that date append issue. If so how? Commented Oct 22, 2020 at 3:48

2 Answers 2

3

One option is to set an environment variable with the base path at startup:

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

Then use "%BASEDIR%/logs/serilog-{Date}.txt" in the config.

Sign up to request clarification or add additional context in comments.

Comments

1

Short: You can't in appsettings.json.

Longer: You can in code via the static PlatformServices class.

PlatformServices.Default.Application.ApplicationBasePath;

and then use replace or whatever you seem fit to replace the ${basedir} with the value returned by ApplicationBasePath, then pass it to your loggers configuration.

Sidenote: You shouldn't use PlatformServices outside of the Startup/Programm class, since they are static and bad to test etc.

2 Comments

Ehhh, it's bad that this is impossible:(
Is it still not supported

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.