屏蔽通过 Serilog 消息传递的异常详细信息

发布于 2025-01-12 08:26:28 字数 1615 浏览 3 评论 0原文

我首先在github上提出的问题: https://github.com/serilog/serilog/issues/ 1657

loggerConfiguration
          .Enrich.FromLogContext()
                .Enrich.WithEnvironmentName()
                .Enrich.WithMachineName()
                .Enrich.WithEnvironmentUserName()
                .Enrich.WithSensitiveDataMasking(MaskingMode.Globally, maskingOperators)
                .Destructure.With(new MaskingOperatorsDestructuringPolicy(maskingOperators));

1657

var testException = new Exception($"{name}: {value}", new Exception($"Inner exception: {name}: {value}"))
            {
                Data = {{name, value}}
            };
            
            _logger.Information($"{name}: {value}");
            _logger.Information(value);
            _logger.Information($"{value}: {name}");
            _logger.Information("{Name}: {Value}", name, value);
            _logger.Information("{@ResultObject}", new { name, value });
            _logger.Information("{@ResultDictionary}", new Dictionary<string, object>() { { name, value } });
            _logger.Information("{@ResultCollection}", new[] { name, value });
            _logger.Information(testException, "Throws an exception with sensitive data");

value 是敏感数据,它被 Serilog.Enrichers.Sensitive 或我的自定义屏蔽运算符解构策略的敏感数据屏蔽所覆盖。

除有例外情况外,所有情况均涵盖在内。这个东西中传递的数据也应该被屏蔽,不是吗?你知道该怎么做吗?我想让它适用于所有水槽。

Issue on github that I firstly made: https://github.com/serilog/serilog/issues/1657

I've got such configuration:

loggerConfiguration
          .Enrich.FromLogContext()
                .Enrich.WithEnvironmentName()
                .Enrich.WithMachineName()
                .Enrich.WithEnvironmentUserName()
                .Enrich.WithSensitiveDataMasking(MaskingMode.Globally, maskingOperators)
                .Destructure.With(new MaskingOperatorsDestructuringPolicy(maskingOperators));

and asserts in my logging test:

var testException = new Exception(
quot;{name}: {value}", new Exception(
quot;Inner exception: {name}: {value}"))
            {
                Data = {{name, value}}
            };
            
            _logger.Information(
quot;{name}: {value}");
            _logger.Information(value);
            _logger.Information(
quot;{value}: {name}");
            _logger.Information("{Name}: {Value}", name, value);
            _logger.Information("{@ResultObject}", new { name, value });
            _logger.Information("{@ResultDictionary}", new Dictionary<string, object>() { { name, value } });
            _logger.Information("{@ResultCollection}", new[] { name, value });
            _logger.Information(testException, "Throws an exception with sensitive data");

name is a property name,
value is a sensitive data that is covered either with sensitive data masking from Serilog.Enrichers.Sensitive or from my custom masking operators destructuring policy.

All situations are covered except the case when we have exception. Data delivered in this thing should be masked as well, shouldn't it? Do you know how to do it? I would like to make it working for all sinks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文