Serilog: Serilog does not write log to file while using InProcess hosting model in ASP.NET Core 2.2

Created on 19 Dec 2018  路  3Comments  路  Source: serilog/serilog

If I use newly introduced InProcess hosting model in ASP.NET Core 2.2 as follows:

```

netcoreapp2.2
InProcess

`Serilog` does not write log to file. but if I remove `<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>` from `.csproj` everything works as expected.

My `Serilog` configuration in the Program class as follows:

public static void Main(string[] args)
{
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Information() // Set the minimun log level
.WriteTo.File("Logs\log-.txt", rollingInterval: RollingInterval.Day, retainedFileCountLimit: 7) // this is for logging into file system
.CreateLogger();

        try
        {
            Log.Information("Starting web host");
            CreateWebHostBuilder(args).Build().Run();
        }
        catch (Exception ex)
        {
            Log.Fatal(ex, "Host terminated unexpectedly");
        }
        finally
        {
            Log.CloseAndFlush();
        }

}
`` How can makeSerilogworkable while usingInProcess` hosting model?

Most helpful comment

I found the answer on a different issue. https://github.com/aspnet/AspNetCore/issues/4206. Also, here is a stackoverflow for an answer. https://stackoverflow.com/questions/53846333/serilog-does-not-write-log-to-file-while-using-inprocess-hosting-model-in-asp-ne

Just incase any one else wanders onto this also. Thanks!

All 3 comments

@TanvirArjel ,Hi. Check the "C:WindowsSystem32inetsrv" directory, since w3wp.exe resides there.

Hi, I am having the same issue. I have checked that directory (the "C:WindowsSystem32inetsrv") and it is not there . When I remove "InProcess" from csproj it works fine. Any recommendations? In the case of the person aboves code, it creates a file (and the logs within the created file) right next to the project where I would expect them to be (this is when the "InProcess" is removed).

I found the answer on a different issue. https://github.com/aspnet/AspNetCore/issues/4206. Also, here is a stackoverflow for an answer. https://stackoverflow.com/questions/53846333/serilog-does-not-write-log-to-file-while-using-inprocess-hosting-model-in-asp-ne

Just incase any one else wanders onto this also. Thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dazinator picture dazinator  路  3Comments

omora-RA picture omora-RA  路  3Comments

amwitx picture amwitx  路  4Comments

fernandezjose picture fernandezjose  路  4Comments

sicollins picture sicollins  路  4Comments