How to check/Write logs of Serilog ?

10. May 2020

Question searched on google .

 

How to check whether Serilog internal exception occurs .

 

Serilog not writing logs to database

 

The given ColumnMapping does not match up with any column in the source or destination serilog

 

 

In order to get to know what is making the Serilog not perform its job of logging in to Database server we will enable the Serilogs self logging .
In order to do that we will have to add these lines to Program.cs in Main method.

 

string pathFile = @"Logs/SeriSelf.log";
var file = System.IO.File.CreateText(pathFile);



public static void Main(string[] args)
        {
            var configuration = new ConfigurationBuilder()
                .AddJsonFile("appsettings.json")
                .Build();
            
            string pathFile = @"Logs/SeriSelf.log";
            var file = System.IO.File.CreateText(pathFile);
            
            Serilog.Debugging.SelfLog.Enable(TextWriter.Synchronized(file));
            Log.Logger = new LoggerConfiguration()
                .ReadFrom.Configuration(configuration)
                .WriteTo.Console()
                .CreateLogger();

            try
            {
                Log.Information("Getting the Application Clanstech Running... ");
                CreateHostBuilder(args).Build().Run();

            }
            catch(Exception ex)
            {
                Log.Fatal(ex, "Host terminated unexpectedly");
            }
            finally
            {
                Log.CloseAndFlush();
            }
        }

Now run the application . You will see a log file named SeriSelf.log in Logs Folder . Open it and check if it has any content then there is some problem else Serilog is running fine .


Now for the Question

 

The given ColumnMapping does not match up with any column in the source or destination serilog

 

This happens when the table column does not match with specification of Serilog internal working . In my case i had created the table Log with column LogId as Primary key which was making this error , hence after changing that to Id everything worked fine .

 

ASP.NET MVC Core, Debugging, Exceptions, Logging, Serilog ,

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading