0

I have added the Serilog to this project but I tried to make it work to no avail the setting I am currently using on appssetings is the project is using ASP.NET Core 7 but it doesnt seem to work at all it allows me to read the log from console but it doesnt create any of the file and I would have liked to create them within a folder

I added s system var Environment.SetEnvironmentVariable("BASEDIR", AppDomain.CurrentDomain.BaseDirectory);

and added the dir onto the file with %BASEDIR%/NonExistingFolder/LogFile/myAssemblylog-{Date}.txt

and it didnt work either


    {
      "Serilog": {
        "Using": [ "Serilog.Sinks.Console", "Serilog.Sinks.File" ],
        "MinimumLevel": {
          "Default": "Debug",
          "Microsoft": "Information",
          "System": "Information"
        },
        "Enrich": [ "FromLogContext", "WithMachineName", "WithProcessId", "WithThreadId" ],
        "WriteTo": [
          {
            "Name": "Console",
            "outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level}] [{SourceContext}] [{EventId}] {Message}{NewLine}{Exception}"
          },
          {
    
            "Name": "File",
            "Args": {
    
              "pathFormat": "\\myAssemblylog-{Date}.txt",
              "rollOnFileSizeLimit": true,
              "outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level}] [{SourceContext}] [{EventId}] {Message}{NewLine}{Exception}",
              "formatter": "Serilog.Formatting.Json.JsonFormatter",
              "rollingInterval": "Day"
            }
          }
        ]
      }
    }

and the packages I am using

    <PackageReference Include="Serilog.AspNetCore" Version="7.0.0" />
    <PackageReference Include="Serilog.Enrichers.Context" Version="4.6.5" />
    <PackageReference Include="Serilog.Enrichers.Environment" Version="2.2.0" />
    <PackageReference Include="Serilog.Enrichers.Process" Version="2.0.2" />
    <PackageReference Include="Serilog.Enrichers.Thread" Version="3.1.0" />
    <PackageReference Include="Serilog.Formatting.Compact" Version="1.1.0" />
    <PackageReference Include="Serilog.Settings.Configuration" Version="7.0.0" />
    <PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
    <PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />```
PontiacGTX
  • 185
  • 2
  • 15

0 Answers0