1

I am trying to change the location of where Serilog files get written to. It will write to a directory at the root of the project or below (example, StructuredLogs/file-here.txt), but any time I attempt to use an env variable or write to an absolute file path or even relative file path, it will only write to the root directory and replace / or \ (properly escaped) with :

VS example

The settings are in the appSettings.json as such:

"Serilog": {
    "Using": [],
    "Properties": {
      "ApplicationName": "Test API"
    },
    "MinimumLevel": {
      "Default": "Debug",
      "Override": {
        "Microsoft": "Debug",
        "Microsoft.TestApi": "Debug",
        "System": "Debug"
      }
    },
    "Enrich": [ "FromLogContext", "WithMachineName", "WithProcessId", "WithProcessName", "WithThreadId" ],
    "WriteTo": [
      { "Name": "Console" },
      {
        "Name": "File",
        "Args": {
          "path": "D:\\repo\\micro-services\\Apis\\structured-logs\\logs.txt",
          "rollingInterval": "Day",
          "outputTemplate": "{Timestamp:G} {Message}{NewLine:1}{Exception:1}"
        }
      },
      {
        "Name": "File",
        "Args": {
          "path": "D:\\repo\\micro-services\\Apis\\structured-logs\\logs.json",
          "rollingInterval": "Day",
          "formatter": "Serilog.Formatting.Json.JsonFormatter, Serilog"
        }
      },

...

I have tried:

  1. Moving the solution to my local computer from a portable drive: C:/ vs D:/
  2. Ensuring it was running with elevated permissions of Visual Studio 2022
  3. changing to the various types of ways I could get to a different directory (relative, absolute, env variable, etc.)
  4. forward-slash vs back-slash

none have worked.

Looks vaguely familiar to a character set encoding issue of some sort, but not sure.

Any thoughts as ideally I would have a relative path?

1 Answers1

0

I use these at program.cs

the log file was saved at parent dictionary Log.Logger = new LoggerConfiguration() .WriteTo.Console() .WriteTo.File("../log-.txt", rollingInterval: RollingInterval.Day) .CreateLogger();

Jackie Z
  • 21
  • 1