Serilog Not Working on .Net Framework 4.7

Viewed 48

So I'm trying to implement logging into my .Net framework Web API project but it doesn't seem to be working for some reason.

I read on their Github page that I need to use Serilog.AspNetCore version 3.4.0 with .Net framework, so I already did that. Now as far as I am aware I don't need to downgrade anything else, since it isn't mentioned in the Github, so the following are the version of dependencies:

Serilog 2.12.0
Serilog.AspNetCore 3.4.0
Serilog.Extentions.Logging 3.0.1
Serilog.Sinks.Debug 1.0.1
Serilog.Sinks.File 5.0.0

Here is my code for logging:

        [HttpGet]
        [Route("api/GetOnboardCaseDetail")]
        [ActionName("LoadNew")]
        public async Task<RF_CASE> GetOnboardCaseDetail(int caseID,CancellationToken cancellationToken)
        {
            Log.Logger = new LoggerConfiguration()
            .WriteTo.File("./logs/myapp.txt", rollingInterval: RollingInterval.Day)
            .WriteTo.Console()
            .CreateLogger();

            Log.Logger.Debug("test");
            Log.Logger.Error("Testt");
            Log.Logger.Information("test");
            Log.CloseAndFlush();

        }

I'm new to ASP .NET but if I understand correctly, when I trigger the API, it should create the myapp.txt file in bin/logs. But when I search the whole project, I cannot find the file text file anywhere. I don't know if I'm supposed to do any other changes or not, as this is all the changes that I have made to the code. Would really appreciate it if someone could point out my mistake here.

1 Answers

Try adding MinimumLevel.Debug() As follows,

Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug()
            .WriteTo.File("./logs/myapp.txt", rollingInterval: RollingInterval.Day)
            .WriteTo.Console()
            .CreateLogger();
Related