Serilog C# 如何防止记录大数据,例如图像数据或大 JSON 对象

发布于 2025-01-16 03:13:48 字数 306 浏览 2 评论 0原文

Serilog 使用 C# 如何防止记录大数据,例如图像数据或大型 JSON 对象

如何配置 serilog 的 Log api 以进行日志记录数据检查以记录输入直到一定程度。

示例:

serilogLoggerInstance.Information("input"); -- input should have check to log if its below a define size. e.g. image data, large JSON object

Serilog using C# how to prevent logging big data e.g. image data or large JSON object

How to configure the Log api of serilog to have logging-data check to log the input till an extent.

Example:

serilogLoggerInstance.Information("input"); -- input should have check to log if its below a define size. e.g. image data, large JSON object

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

慵挽 2025-01-23 03:13:48

我认为记录大量数据在某些情况下可能很有用,但可能只应在调查某些错误时根据特定请求进行记录。所以我的建议是制定一些关于应该记录什么、记录到什么级别以及记录频率的策略。请记住,您可以记录到多个级别:

serilogLoggerInstance.Information("Received image of size: {image.Size}");
serilogLoggerInstance.Verbose("Received image Data: {image.Data}");

强制执行某些限制的问题是限制应该是什么。如果太小,您将丢失重要的日志信息。如果太大,则日志大小不会减少太多。一些技术解决方案对于找到不良日志消息的来源可能仍然有价值,但我不知道如何在 Serilog 中实现类似的东西。您始终可以为记录器创建一个装饰器,但这只有在注入记录器并且不使用某些静态工厂或实例时才可行。

I would argue that logging large amount of data could be useful in some cases, but it should probably only be logged on specific request when investigating some bug. So my advice would be to establish some policy regarding what should be logged, to what level and how frequently. Keep in mind that you can log to multiple levels:

serilogLoggerInstance.Information("Received image of size: {image.Size}");
serilogLoggerInstance.Verbose("Received image Data: {image.Data}");

A problem with enforcing some limit is what the limit should be. To small and you will lose important logging information. To large and you will not reduce the log size much. Some technical solution might still be valuable to find the sources of poor log messages, but I have no idea how to implement something like that in serilog. You could always create a decorator for the logger, but that would only be feasible if you inject the logger, and are not using some static factory or instance.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文