I'm using .net Core 2.0 and Serilog Email sink. I have problem to configure email sink with appsettings.json
. The same configuration from program.cs
is working while one from appsetting.json
isn't.
相关问题
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Easiest way to get json and parse it using JQuery
- Newtonsoft DeserializeXNode expands internal array
相关文章
- json_encode 没有把数组转为json
- Livy Server: return a dataframe as JSON?
- Unexpected end of JSON input from an ajax call
- How do I do a nested list (array) of schema refere
- DotNet Core console app: An assembly specified in
- iconv() Vs. utf8_encode()
- Convert C# Object to Json Object
- How do I make a forward e-mail link?
The settings system (
ReadFrom.Configuration()
) really only does try to call methods and extension methods that it can discover and pass arguments provided from the configuration file.Unfortunately, it only supports basic types for the time being (convertible to/from
string
and a few more specific cases) and therefore, parameters of typeEmailConnectionInfo
cannot be provided.As a workaround, though, if you only need to pass in a few parameters, you can create your own extension method that accepts the parameters that you need and call it from the configuration system.
In your case, you would need to do the following :
First, define an extension method
EmailCustom(...)
that can be plugged onWriteTo
(which is of typeSerilog.Configuration.LoggerSinkConfiguration
) and returns aLoggerConfiguration
.This would look something like (not tested, no usings etc :P) :
From that point on, you should be able to write C# code like :
Once you have that working, you can actually define that method call in json thanks to Serilog.Settings.Configuration in that case, that would look like
This strategy can be applied for other sinks and other configuration parts of Serilog as well.
You can find a bit more about the configuration system here :