-
Notifications
You must be signed in to change notification settings - Fork 147
Additional Column - Static Value #575
-
Hi all, question about using this sink. I am evaluating a migration to Serilog + Serilog-Sinks-MSSqlServer + M.E.L, injecting a M.E.L.ILogger<TSelf>
in whatever type where I need log.
In our current logs table, we have a column called ApplicationId
, and this value is currently passed to a custom M.E.L logger via an IConfiguration value which just inserts this value alongside any logging request.
I understand that this sink will allow me to define additional columns, but unlike an additional property like a user context id for ASP.NET logging, this value is read once when the application starts and never changes.
Is it possible out of the box, perhaps by definining some sort of "default" value for the column, to specify an application-wide value for an additional column?
Beta Was this translation helpful? Give feedback.
All reactions
Hi @Foxtrek64!
The MSSQL sink currently does not support default values for columns if a corresponding property was not provided. You can take a look at the following possible solutions.
- Write a Serilog enricher to set your custom properties to default values
- Use SQL server to fill in default values (by schema definition, insert trigger, etc.)
Replies: 1 comment 1 reply
-
Hi @Foxtrek64!
The MSSQL sink currently does not support default values for columns if a corresponding property was not provided. You can take a look at the following possible solutions.
- Write a Serilog enricher to set your custom properties to default values
- Use SQL server to fill in default values (by schema definition, insert trigger, etc.)
Beta Was this translation helpful? Give feedback.
All reactions
-
Thanks for the tips! I did some digging into Serilog Enrichers and found a couple of options:
.Enrich.WithProperty("ApplicationId", hostBuilder.Configuration["ApplicationId"])
- The Global Log Context enricher here: https://github.com/serilog-contrib/serilog-enrichers-globallogcontext
I think for simplicity's sake, since this is something registered at startup and never changing, I'll try with the first one first, but if my needs grow the global log context enricher will take care of any needs.
Beta Was this translation helpful? Give feedback.