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

configureLogger doesn't work for published app #340

Open
SvetlanaLevi opened this issue Nov 28, 2022 · 1 comment
Open

configureLogger doesn't work for published app #340

SvetlanaLevi opened this issue Nov 28, 2022 · 1 comment

Comments

@SvetlanaLevi
Copy link

SvetlanaLevi commented Nov 28, 2022

I need to specify different filters for each sink and example above is working correctly in debug mode, but after publishing application as self-contained logs failed to write.

{
  "Serilog": {
    "MinimumLevel": "Debug",
    "Using": [
      "Serilog.Sinks.Console",
      "Serilog.Sinks.File",
      "Serilog.Expressions"
    ],
    "WriteTo": [
      {
        "Name": "Logger",
        "Args": {
          "configureLogger": {
            "Filter": [
              {
                "Name": "ByExcluding",
                "Args": {
                  "expression": "StartsWith(SourceContext, 'System.Net.Http.HttpClient.HttpMarkingService.LogicalHandler')"
                }
              }
            ],
            "WriteTo": [
              {
                "Name": "Console",
                "Args": {
                  "outputTemplate": "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj} {NewLine}"
                }
              }
            ]
          }
        }
      },
      {
        "Name": "Logger",
        "Args": {
          "configureLogger": {
            "WriteTo": [
              {
                "Name": "File",
                "Args": {
                  "path": "log.txt",
                  "outputTemplate": "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj} <s:{SourceContext}>{NewLine}{Exception}"
                }
              }
            ]
          }
        }
      }
    ]
  }
}

Without nested "WriteTo" sections it works fine.

@0xced
Copy link
Member

0xced commented Feb 6, 2023

You might want to try the overload that takes an explicit list of assemblies when publishing as single file.

var configurationAssemblies = new[]
{
    typeof(SerilogExpression).Assembly,                    // Serilog.Expressions
    typeof(ConsoleLoggerConfigurationExtensions).Assembly, // Serilog.Sinks.Console
    typeof(FileLoggerConfigurationExtensions).Assembly,    // Serilog.Sinks.File
};
loggerConfiguration.ReadFrom.Configuration(configuration, configurationAssemblies);

You might also want to enable Serilog self logs in order to diagnose potential issues.

SelfLog.Enable(Console.Error);

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

2 participants