Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Additional Column - Static Value #575

Answered by ckadluba
TheBrambleShark asked this question in Q&A
Discussion options

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?

You must be logged in to vote

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

Comment options

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.)
You must be logged in to vote
1 reply
Comment options

Thanks for the tips! I did some digging into Serilog Enrichers and found a couple of options:

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.

Answer selected by TheBrambleShark
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /