Skip to content

Configuration using appsettings.json #20

Answered by augustoproiete
rs-maja asked this question in Q&A
Discussion options

You must be logged in to vote

No, it's no possible to use the ReadFrom.Configuration. The sink requires a reference to an existing RichTextBox control that it can write to, so the configuration must be done via code.

That said, you can store some parameters like output template and minimum level in a custom section inside of your config file, and then read those values yourself.

e.g.

{
    "serilogRichTextBox": {
        "outputTemplate": "[{Timestamp:HH:mm:ss} {SourceContext} [{Level}] {Message}{NewLine}{Exception}",
        "minimumLevel": "Information"
    }
}
var serilogRichTextBoxConfig = configuration.GetSection("serilogRichTextBox");
var rtbOutputTemplate = serilogRichTextBoxConfig.GetValue<string>("outputTemplate

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by augustoproiete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #19 on September 29, 2021 17:37.