简体   繁体   中英

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

Serilog using C# how to prevent logging big data eg 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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM