【发布时间】:2018-10-18 11:29:13
【问题描述】:
我目前正在尝试更改我们的系统配置以使用 Serilog (而不是使用 FileBeat 作为 LogStash 的托运人)
我们还在各种查询中使用日志 type 字段(很容易在 FileBeat 配置文件中配置)并在 Elastic 上索引日志。
问题是在使用 Serilog 时,我们得到了默认类型 logevent,我没有找到可以配置它的地方。 我想有一个选项来确定每个 Serilog 实例的特定日志类型。 目前我的所有日志都有默认类型。
我的 Serilop 配置是:
var path = GetLogPath();
var logger = new LoggerConfiguration()
.MinimumLevel.Information()
.Enrich.WithMachineName()
.Enrich.WithProperty("RequestId", Guid.NewGuid())
.WriteTo.RollingFile(
pathFormat: path,
outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u4}] [{RequestId}] {Message}{NewLine}{Exception}", buffered: false, shared: true);
logger.WriteTo.Elasticsearch(
new ElasticsearchSinkOptions(new Uri(this.configurationService.ElasticSearchUrl())));
如何更改日志类型?
编辑
经过一番调查,我发现我想更改 LoggerConfiguration 中提交的 typeName 并且似乎我只能通过 AppConfig 文件这样做,如果我要更改它,这又是一次事件,更改将影响所有记录器实例。
我错过了什么吗?
【问题讨论】:
-
更多关于
type对您的意义的信息。一般来说,在 Serilog 中,如果您指的是与记录器关联的类型,则可以将{SourceContext}属性作为标记放入发出格式中。如果您的意思是消息模板的 id,github.com/serilog/serilog-formatting-compact 将为您提供线索。 (我对 ES 接收器的了解为零(显然),但如果您发出 json,您通常可以使用该格式来指导要包含的内容) -
thanx Ruben,我读了一些关于这个属性的文章,这听起来确实是个好习惯。我不确定它是否会解决我与 Elelastic 中的日志索引相关的问题
标签: c# elasticsearch serilog elasticsearch-net