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

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

Closed
alberk8 opened this issue Dec 12, 2020 · 5 comments
Closed

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

alberk8 opened this issue Dec 12, 2020 · 5 comments

Comments

@alberk8
Copy link

alberk8 commented Dec 12, 2020

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.

@pedroansilva
Copy link

Just to add that I'm having the exact same issue while running a .NET5 single file deployment (ex: dotnet publish -c release -r win10-x64 /p:PublishSingleFile=true) in a plain Windows command line. If I publish the exact same application in non single file deployment (ex: dotnet publish -c release -r win10-x64), everything seems to work as expected. Just for reference, please consider this blog post from Scott Hanselman: https://www.hanselman.com/blog/how-do-i-find-which-directory-my-net-core-console-application-was-started-in-or-is-running-from, more importantly the notes about .NET5 at the end of the blog post.

@skomis-mm skomis-mm transferred this issue from serilog/serilog-aspnetcore Dec 12, 2020
@skomis-mm
Copy link
Contributor

skomis-mm commented 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.

@skomis-mm
Copy link
Contributor

skomis-mm commented Dec 12, 2020

Auto-discovery of configuration assemblies for .NET Core relies on application's .deps.json file (via Microsoft.Extensions.DependencyModel API).

As far as I can tell, the .deps.json file is embedded to the AppHost of single file for .NET 5 after publish, but it is not (yet) accessible via managed/public API.

@mc0re
Copy link

mc0re commented 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.

@EmirhanAksoy
Copy link

EmirhanAksoy commented Sep 15, 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.

same here @HakamFostok

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

No branches or pull requests

5 participants