我正在使用 EcsTextFormatter,但我发现您可以拥有自定义映射。我想删除主机字段,但我不确定如何在自定义映射中执行此操作。
我在代码中将其设置为这样,但 MapCustom 不会采用这两个参数。
var config = new EcsTextFormatterConfiguration();
config.MapCustom((EcsDocument ecs1, LogEvent logEvent, EcsDocument ecs2) =>
{
ecs.Host = null;
});
但是我从 MapCustom 收到此错误。
Severity Code Description Project File Line Suppression State
Error CS7036 There is no argument given that corresponds to the required formal parameter 'arg2' of 'Func<EcsDocument, LogEvent, EcsDocument>' TestPOC
要排除主机属性,您不需要向 MapCustom 提供函数, 您只需使用 IncludeHost 配置选项即可。
var config = new EcsTextFormatterConfiguration()
{
IncludeHost = false
}
如果您确实想使用 MapCustom,您应该更改语法。 MapCustom 有两个参数:EcsDocument 和 LogEvent。它返回一个 EcsDocument
MapCustom = (EcsDocument ecs1, LogEvent logEvent) =>
{
// Configure ecs2 based on ecs1 and logEvent
var ecs2 = ...
return ecs2;
}