I created a new .NET Core web project using Visual Studio and integrated Serilog. It reads settings from the appsettings.json (via .UseSerilog((ctx, config) => { co
Ideally, you don't want to write log files to the content root of your web app, since these could end up being accessible over the web, which would be a serious security consideration.
The log file path configuration can include environment variables, so something like %TMP%\log.txt
, or a path based on %LOCALAPPDATA%
etc. is a good option (as long as the web site's worker process has permission to write to the location).
You can write to a path that's relative to your web app by changing the current directory before setting up the logger:
Environment.CurrentDirectory = AppContext.BaseDirectory;
Or, you can combine these approaches and set your own environment variable to do it:
Environment.SetEnvironmentVariable("BASEDIR", AppContext.BaseDirectory);
Thus the following config:
"%BASEDIR%\logs\log.txt"