Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to store different types of logs in different files #435

Open
SunnyVachhetA opened this issue Sep 5, 2024 · 0 comments
Open

How to store different types of logs in different files #435

SunnyVachhetA opened this issue Sep 5, 2024 · 0 comments

Comments

@SunnyVachhetA
Copy link

.NET 8
<PackageVersion Include="Serilog" Version="4.0.1" />
<PackageVersion Include="Serilog.AspNetCore" Version="8.0.2" />
<PackageVersion Include="Serilog.Expressions" Version="5.0.0" />
<PackageVersion Include="Serilog.Sinks.Console" Version="6.0.0" />
<PackageVersion Include="Serilog.Sinks.File" Version="6.0.0" />
{
  "Serilog": {
    "Using": [
      "Serilog.Sinks.Console",
      "Serilog.Sinks.File"
    ],
    "MinimumLevel": {
      "Default": "Information",
      "Override": {
        "Microsoft.AspNetCore.Mvc": "Warning",
        "Microsoft.AspNetCore.Routing": "Warning",
        "Microsoft.AspNetCore.Hosting": "Warning"
      }
    },
    "WriteTo": [
      {
        "Name": "Console"
      },
      {
        "Name": "File",
        "Args": {
          "path": "Logs/log-.txt",
          "rollingInterval": "Day",
          "outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] {Message:lj}{NewLine}{Exception}",
          "fileSizeLimitBytes": 10485760,
          "rollOnFileSizeLimit": true,
          "shared": true,
          "flushToDiskInterval": 1
        },
        "Filter": [
          {
            "Name": "ByIncluding",
            "Args": {
              "expression": "StartsWith(SourceContext, 'Microsoft.EntityFrameworkCore.Database')"
            }
          }
        ]
      }
    ],
    "Enrich": [
      "FromLogContext"
    ]
  },
  "AllowedHosts": "*"
}
//Program.cs file
builder.Host.UseSerilog((context, config) => config.ReadFrom.Configuration(context.Configuration));

I want to store EF Core related query only in Log file, I will have another file for other type of logging.

I tried using Expression but didn't worked. What I am doing wrong?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant