有Serilog.Sinks.PostgreSQL
接收器在asppsettings.json中有自己的配置吗?
这样的事情:
"Serilog": {
...
"WriteTo": [
{
"Name": "PostgreSQL",
"Args": {
"connectionStringName": "Default",
"tableName": "Log",
...
"columnOptions": [
{
...
}
]
}
},
...
答案 0 :(得分:1)
您可以使用Serilog.Settings.Configuration
从那里添加自己的配置。
这里有一个很好的例子:github of seriog app-setting
我猜你的情况看起来像是:
var configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile(path: "appsettings.json", optional: false, reloadOnChange: true)
.Build();
var logger = new LoggerConfiguration()
.ReadFrom.Configuration(configuration)
.CreateLogger();
当您的配置看起来像:
{
"Serilog": {
"Using": ["Serilog.Sinks.Postgresql"],
"MinimumLevel": "Debug",
"WriteTo": [
{ "Name": "Console" },
{ "Name": "File", "Args": { "path": "%TEMP%\\Logs\\serilog-configuration-sample.txt" } }
],
"Enrich": ["FromLogContext", "WithMachineName", "WithThreadId"],
"Destructure": [
{ "Name": "With", "Args": { "policy": "Sample.CustomPolicy, Sample" } },
{ "Name": "ToMaximumDepth", "Args": { "maximumDestructuringDepth": 4 } },
{ "Name": "ToMaximumStringLength", "Args": { "maximumStringLength": 100 } },
{ "Name": "ToMaximumCollectionCount", "Args": { "maximumCollectionCount": 10 } }
],
"Properties": {
"Application": "Sample"
}
}
}
您可以在此处获取更多信息gitub of Serilog setting