Skip to content

Instantly share code, notes, and snippets.

@ddikman
Created February 1, 2016 10:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ddikman/acdc9169204d906e53d9 to your computer and use it in GitHub Desktop.
Save ddikman/acdc9169204d906e53d9 to your computer and use it in GitHub Desktop.
Serilog Json configuration reader
public class LoggerSettings : ILoggerSettings
{
private readonly IConfigurationSection _configuration;
public LoggerSettings(IConfigurationSection configuration)
{
_configuration = configuration;
}
public IEnumerable<KeyValuePair<string, string>> Configurations
{
get
{
foreach (var childSection in _configuration.GetChildren())
{
yield return new KeyValuePair<string, string>(childSection["key"], childSection["value"]);
}
}
}
public void Configure(LoggerConfiguration loggerConfiguration)
{
loggerConfiguration.ReadFrom.KeyValuePairs(Configurations);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment