How to check the handled Exceptions during debug ? in Visual Studio 2019

10. May 2020

Question searched on google

How to check which exception is firing even when it is handled in code using Visual Studio 2019

 

I have thrown an exception in my privacy action as below code shows

throw new NotImplementedException();

 



Run the web application in Debug mode.

Now when i goto privacy action in browser nothing happens as the thrown exception has been caught in my code . Suppose you want to check all the exceptions who are caught and handled during the runtime then what will you do .

Open the Exceptions Settings Window in Bottom of Visual Studio 2019 when application is running.


Now check the Common Language Runtime Exceptions Checkbox .

 



Load the privacy action again in browser , this time you will see the exception thrown and execution breaking the code line of throw new NotImplementedException();

 

 

By this method you can check all the exceptions thrown in a large project even when they are handled .

Debugging, Exceptions, Visual Studio 2019 ,

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 ,