Movatterモバイル変換


[0]ホーム

URL:


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

A Serilog configuration provider that reads from Microsoft.Extensions.Configuration

License

NotificationsYou must be signed in to change notification settings

nblumhardt/serilog-settings-configuration

 
 

Repository files navigation

A Serilog settings provider that reads fromMicrosoft.Extensions.Configuration, .NET Core'sappsettings.json file.

Configuration is read from theSerilog section.

{"Serilog": {"Using":  ["Serilog.Sinks.Literate"],"MinimumLevel":"Debug","WriteTo": [      {"Name":"LiterateConsole" },      {"Name":"File","Args": {"path":"%TEMP%\\Logs\\serilog-configuration-sample.txt" } }    ],"Enrich": ["FromLogContext","WithMachineName","WithThreadId"],"Properties": {"Application":"Sample"    }  }}

This example relies on theSerilog.Sinks.Literate,Serilog.Sinks.File,Serilog.Enrichers.Environment andSerilog.Sinks.Thread packages also being installed.

After installing this package, useReadFrom.Configuration() and pass anIConfiguration object.

publicclassProgram{publicstaticvoidMain(string[]args){varconfiguration=newConfigurationBuilder().AddJsonFile("appsettings.json").Build();varlogger=newLoggerConfiguration().ReadFrom.Configuration(configuration).CreateLogger();logger.Information("Hello, world!");}}

TheWriteTo andEnrich sections support the same syntax, for example the following is valid if no arguments are needed by the sinks:

"WriteTo": ["LiterateConsole","DiagnosticTrace"]

Or alternatively, the long-form ("Name": ...) sytax from the first example can be used when arguments need to be supplied.

(This package implements a convention usingDependencyContext to find any package withSerilog anywhere in the name and pulls configuration methods from it, so theUsing example above is redundant.)

.NET 4.x

To use this package in .NET 4.x applications, addpreserveCompilationContext tobuildOptions inproject.json.

"net4.6": {"buildOptions": {"preserveCompilationContext":true   }},

About

A Serilog configuration provider that reads from Microsoft.Extensions.Configuration

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C#97.3%
  • PowerShell2.7%

[8]ページ先頭

©2009-2025 Movatter.jp