serilog-sinks-mssqlserver icon indicating copy to clipboard operation
serilog-sinks-mssqlserver copied to clipboard

Exception column is always null

Open xjpmauricio opened this issue 4 years ago • 3 comments

Bug Report / Support Request Template

If you are opening a feature request, you can ignore this template. Bug reports and requests for assistance usually require the same basic information described below. This will help us more quickly reproduce and investigate the problem you're reporting. (If you are using Serilog.Sinks.MSSqlServerCore, that package is deprecated, please switch to Serilog.Sinks.MSSqlServer before reporting an issue.)

Please clearly describe what the SQL Sink is doing incorrectly: The Exception column is always null on my database table.

Please clearly describe the expected behavior: See the exception details.

List the names and versions of all Serilog packages used in the project:

  • Serilog: Serilog.AspNetCore 4.1.0
  • Serilog.Sinks.MSSqlServer: 5.6.1
  • (configuration, etc.)

Target framework and operating system:

[x ] .NET Core 2.0 [ ] .NET Framework 4.7 [ ] .NET Framework 4.6.x [ ] .NET Framework 4.5.x OS:

Provide a simple reproduction of your Serilog configuration code: public static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args) .ConfigureServices((hostContext, services) => { Log.Logger = new LoggerConfiguration() .Enrich.FromLogContext() .ReadFrom.Configuration(hostContext.Configuration). CreateLogger();
}) .UseSerilog() .ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup<Startup>(); }); public static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args) .ConfigureServices((hostContext, services) => { // https://serilog.net/ // https://github.com/serilog/serilog/wiki/Configuration-Basics // https://github.com/serilog/serilog-sinks-mssqlserver Log.Logger = new LoggerConfiguration() .Enrich.FromLogContext() .ReadFrom.Configuration(hostContext.Configuration). CreateLogger();
}) .UseSerilog() .ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup<Startup>(); });

Provide a simple reproduction of your Serilog configuration file, if any: "Serilog": { "MinimumLevel": "Information", "WriteTo": [ { "Name": "MSSqlServer", "Args": { "connectionString": "Data Source=localhost;Initial Catalog=MyLog;User Id=sa;Password=asdassadasd;", "tableName": "MyDatabaseName", "autoCreateSqlTable": true } } ] },

Provide a simple reproduction of your application code: try { int aaa = Convert.ToInt32("error"); } catch(Exception ex) { _logger.LogError("TEST", ex); }

xjpmauricio avatar Oct 19 '21 17:10 xjpmauricio

Hi @xjpmauricio!

The sink contains a CustomLogEventFormatterDemo sample app. It uses the following code to log an exception.

​catch​ (​DivideByZeroException​ ​e​) 
​{ 
​       Log​.​Error​(​e​, ​"​Division by zero​"​); 
​}

Your code uses a method named LogError with a different signature. To rule out a problem there, please try to use Log​.​Error​(...) instead.

ckadluba avatar Jan 02 '22 15:01 ckadluba

Hi @xjpmauricio!

The sink contains a CustomLogEventFormatterDemo sample app. It uses the following code to log an exception.

​catch​ (​DivideByZeroException​ ​e​) 
​{ 
​       Log​.​Error​(​e​, ​"​Division by zero​"​); 
​}

Your code uses a method named LogError with a different signature. To rule out a problem there, please try to use Log​.​Error​(...) instead.

Hi, I think Log​.​Error​ belongs to the Serilog library, I want to use the method from Microsoft.Extensions.Logging. Is it possible? The log is being added but the only thing that's missing is the exception column not being filled.

xjpmauricio avatar Jan 03 '22 11:01 xjpmauricio

Can you provide a complete sample program for us to reproduce this? I mean including a solution and project similar to the one you have.

ckadluba avatar Feb 21 '22 13:02 ckadluba