c# - 如何修复无效的 URI:在 asp.net 核心问题中无法确定 URI 的格式
问题描述
我在我的 Asp.net 核心程序中使用 serilog 和 Seq,但我不断收到上述错误。我的 Seq 服务器正在运行。appsetting.json
分别在和中找到下面的配置startup.cs
。
应用设置.json
"Serilog": {
"Destructure": [
{
"Name": "With",
"Args": { "policy": "Sample.CustomPolicy, Sample" }
},
{
"Name": "ToMaximumDepth",
"Args": { "maximumDestructuringDepth": 4 }
},
{
"Name": "ToMaximumStringLength",
"Args": { "maximumStringLength": 100 }
},
{
"Name": "ToMaximumCollectionCount",
"Args": { "maximumCollectionCount": 10 }
}
],
"Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId" ],
"MinimumLevel": "Debug",
"Properties": {
"Application": "Sample"
},
"Using": [ "Serilog.Sinks.File", "Serilog.Sinks.Async", "Serilog.Sinks.Console", "Serilog.Sinks.Seq", "Serilog.Sinks.Graylog" ],
"WriteTo": [
{
"Name": "Console"
},
{
"Name": "File",
"Args": { "path": "Loggers/logs.txt" }
},
{
"Args": {
"serverUrl": "http://localhost:5341"
},
"Name": "Seq"
}
]
}
启动.cs
services.AddLogging(loggingBuilder =>
{
loggingBuilder.AddSeq("Seq");
});
解决方案
对于loggingBuilder.AddSeq("Seq");
,您需要传递 url 而不是Seq
.
//
// Summary:
// Extends Microsoft.Extensions.Logging.ILoggerFactory with methods for configuring
// Seq logging.
public static class SeqLoggerExtensions
{
//
// Summary:
// Adds a Seq logger configured from the supplied configuration section.
//
// Parameters:
// loggerFactory:
// The logger factory.
//
// configuration:
// A configuration section with details of the Seq server connection.
//
// Returns:
// A logger factory to allow further configuration.
public static ILoggerFactory AddSeq(this ILoggerFactory loggerFactory, IConfigurationSection configuration);
//
// Summary:
// Adds a Seq logger.
//
// Parameters:
// loggerFactory:
// The logger factory.
//
// serverUrl:
// The Seq server URL; the default is http://localhost:5341.
//
// apiKey:
// A Seq API key to authenticate or tag messages from the logger.
//
// minimumLevel:
// The level below which events will be suppressed (the default is Microsoft.Extensions.Logging.LogLevel.Information).
//
// levelOverrides:
// A dictionary mapping logger name prefixes to minimum logging levels.
//
// Returns:
// A logger factory to allow further configuration.
public static ILoggerFactory AddSeq(this ILoggerFactory loggerFactory, string serverUrl = "http://localhost:5341", string apiKey = null, LogLevel minimumLevel = LogLevel.Information, IDictionary<string, LogLevel> levelOverrides = null);
//
// Summary:
// Adds a Seq logger.
//
// Parameters:
// loggingBuilder:
// The logging builder.
//
// serverUrl:
// The Seq server URL; the default is http://localhost:5341.
//
// apiKey:
// A Seq API key to authenticate or tag messages from the logger.
//
// Returns:
// A logging builder to allow further configuration.
public static ILoggingBuilder AddSeq(this ILoggingBuilder loggingBuilder, string serverUrl = "http://localhost:5341", string apiKey = null);
//
// Summary:
// Adds a Seq logger configured from the supplied configuration section.
//
// Parameters:
// loggingBuilder:
// The logging builder.
//
// configuration:
// A configuration section with details of the Seq server connection.
//
// Returns:
// A logging builder to allow further configuration.
public static ILoggingBuilder AddSeq(this ILoggingBuilder loggingBuilder, IConfigurationSection configuration);
}
如果要从 传递配置appsettings.json
,请定义appsettings.json
类似
"Seq": {
"ServerUrl": "http://localhost:5341",
"ApiKey": "1234567890",
"MinimumLevel": "Trace",
"LevelOverride": {
"Microsoft": "Warning"
}
}
并使用 like loggingBuilder.AddSeq(Configuration.GetSection("Seq"));
。
如果您需要结合serilog
and Seq
,请参阅使用 Serilog。
Log.Logger = new LoggerConfiguration()
.WriteTo.Console()
.WriteTo.Seq("http://localhost:5341")
.CreateLogger();
推荐阅读
- python - Python 每个循环创建/分配一个值到一个变量是否比在循环外创建/分配一个变量需要更多的内存/时间?
- html - 无法让此 IPCONFIG 命令显示在HTML 标签
- django - Django ORM - 过滤器不适用于集合
- c# - 使用依赖注入在类上实现接口
- android - 在项目“:app”中找不到任务“installDebug”。- 在反应原生
- azure - 运行 az vm 命令需要哪些权限?
- loops - 为什么我的函数不会按预期循环?
- java - @Transactional 注解覆盖了 Mockito 的 InjectMocks
- django - 在两个模型字段范围内搜索日期范围
- javascript - 使用ajax动态加载模态细节