question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Aspnet Core 5 single file deploy with Serilog - no log output

See original GitHub issue

The Serilog maintainers want you to have a great experience using Serilog, and will happily track down and resolve bugs. We all have limited time, though, so please think through all of the factors that might be involved and include as much useful information as possible 😊.

ℹ If the problem is caused by a sink or other related package, please try to track down the correct repository for that package and create the report there: this tracker is for the Serilog.AspNetCore package only.

Description There is no log output to console or log file

Reproduction program.cs

 public static void Main(string[] args)
        {
            //var _config = new ConfigurationBuilder().AddJsonFile("appsettings.json");
            
            //Log.Logger = new LoggerConfiguration()
            //.MinimumLevel.Information()
            //.MinimumLevel.Override("Microsoft", LogEventLevel.Information)
            //.Enrich.FromLogContext()
            //.WriteTo.Console()
            //.ReadFrom.Configuration(_config.Build())
            //.CreateLogger();

            CreateHostBuilder(args).Build().Run();
        }

        public static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
                .UseSerilog((hostingContext, services, loggerConfiguration) => loggerConfiguration
                    .ReadFrom.Configuration(hostingContext.Configuration)
                    .Enrich.FromLogContext())
                .ConfigureWebHostDefaults(webBuilder =>
                {
                    webBuilder.UseStartup<Startup>();
                });
    }

appsettings.json

{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft": "Warning",
      "Microsoft.Hosting.Lifetime": "Information"
    }
  },
  "AllowedHosts": "*",
  "Serilog": {
    "MinimumLevel": {
      "Default": "Information",
      "Override": {
        "Microsoft": "Information"
      }
    },
    "WriteTo": [
      {
        "Name": "Console",
        "Args": {
          "outputTemplate": "[{Timestamp:HH:mm:ss.fff} {Application} {Level:u3}][{RequestId}] {SourceContext}: {Message:lj}{NewLine}{Exception}"
        }
      },
      {
        "Name": "File",
        "Args": {
          "outputTemplate": "[{Timestamp:HH:mm:ss.fff} {Application} {Level:u3}][{RequestId}] {SourceContext}: {Message:lj}{NewLine}{Exception}",
          "path": "/var/log/aspnetcore5/applog.log",
          "fileSizeLimitBytes": 100485760,
          "rollOnFileSizeLimit": true,
          "rollingInterval": "Day",
          "retainedFileCountLimit": 3
        }
      }

    ]
  }
}

Expected behavior logs to console and file. The same app works in dotnet core 3.1

Relevant package, tooling and runtime versions What Serilog version are you using, on what platform? Serilog.AspNetCore 3.4.0 Docker image Alpine 3.12 x64 from Microsoft https://github.com/dotnet/dotnet-docker/tree/master/src/aspnet/5.0/alpine3.12/amd64

Additional context The same app works when it is not bundled/compiled into a single file or standalone deployment.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
skomis-mmcommented, Dec 12, 2020

Hi, @alberk8, @pedroansilva See issues: #245, #239. I’ve updated the documentation here:

Currently, auto-discovery of configuration assemblies is not supported in bundled mode. Use Using section for workaround.

2reactions
mc0recommented, Mar 4, 2021

I had a similar problem when switching the project to .NET 5. What solved it is moving the configuration from appsettings.json to code - and not reading the JSON file.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Serilog does not output logs into the txt file
Im using dotnet worker service (.net 5) I integrated serilog as well as enrichers and sinks. But for some reason I dont see...
Read more >
Setting up Serilog in ASP.NET Core - Detailed Beginner ...
This article covers the implementation of Serilog in ASP.NET Core which provides structured logging that is easier to be read by programs.
Read more >
Logging in ASP.NET Core 5 using Serilog
Learn how to configure Serilog logging library in ASP.NET Core, Learn to output logs in text and JSON, Learn how to log output...
Read more >
Logging with Serilog in ASP.NET Core Web API
Learn how to implement logging with Serilog in ASP.NET Core Web API, through easy steps you will be able to add Serilog into...
Read more >
How to Use Serilog in ASP.NET Core Web API
Learn how to use Serilog in .NET applications. It offers a simple interface for .NET logging and countless log targets (sinks).
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found