Extracting ExceptionDetail Child Property Values Into SqlColumn #733
Replies: 3 comments
-
You probably want to create an NVARCHAR column in SQL Server for the value of Message. |
Beta Was this translation helpful? Give feedback.
-
Thanks @RehanSaeed. I've confirmed both the SqlColumn specifies |
Beta Was this translation helpful? Give feedback.
-
I also tested a few more times in different scenarios and confirmed the same non-JSON output when setting the SqlColumn |
Beta Was this translation helpful? Give feedback.
-
I'm working with Serilog.Exceptions and it is enriching correctly (thank you very much BTW). I am looking to extract properties of ExceptionDetail and insert them into their own database columns. I'm using SQL Server and when referencing the
ExceptionDetail.Type
andExceptionDetail.Message
as thePropertyName
value in the SqlColumn, they always insert NULLs into their respective columns. After further investigation, I'm noticing that the rendered value of ExceptionDetail is not JSON (as opposed to the other properties). When I putExceptionDetail
as thePropertyName
value in the SqlColumn, I get this non-JSON formatted data:[("Type": "System.ArgumentException"), ("HResult": -2147024809), ("Message": "This is a manually generated ArgumentException."), ("Source": "Library.ResearchX"), ("StackTrace": " at Library.ResearchX.Controllers.LogsController.GenerateTestError(String errorType) in C:\Users\user\source\repos\website\Library.ResearchX\Controllers\LogsController.cs:line 116 at lambda_method244(Closure, Object, Object[]) [removed for brevity]"), ("TargetSite": "Microsoft.AspNetCore.Mvc.ActionResult GenerateTestError(System.String)"), ("ParamName": null)]
I would have expected this to be JSON - or correct me if I'm wrong there, and thus, am assuming this is why the value is inserting NULL. For example, when I attempt to extract the
ExceptionDetail.Message
value into a SqlColumn like so:new SqlColumn {ColumnName = "ExceptionMessage", PropertyName = "ExceptionDetail.Message", DataType = SqlDbType.NVarChar},
it simply inserts NULL.
For comparison, when inserting the
EventId
property (which has child propertiesId
andName
, it is rendered as proper JSON like so:{ Id: 1, Name: "UnhandledException" }
Any thoughts on why the
ExceptionDetail
value is rendered in a non-JSON format? Is that formatting the cause of why the value is not being pulled into the SqlColumn when referencingExceptionDetail.Message
?Beta Was this translation helpful? Give feedback.
All reactions