0

I'm using a JSON log sink which destructures complex properties. For some reason, Microsoft has this log built-in when you return a file content result from your controller action:

Executing {FileResultType}, sending file with download name '{FileDownloadName}' ...

Tat FileResultType has a nested property which includes the actual byte array, so my log space will be blown out if I don't get rid of this.

json log snippet

I know how to filter out a specific logger by name, so I can do that.. But I really just don't want this specific object to be logged out. I still find the rest of the message very helpful. I'm not sure if there's a flag I can toggle to bypass this or what since Microsoft is definitely aware that many people are using log sinks which serialize complex objects instead of just calling .ToString(), but I haven't found anything yet. I'm using NLog so I'm sure I can get creative there with some if conditions, but it'd be pretty inefficient because that check would have to run on every single log attempt.

user15716642
  • 171
  • 1
  • 12
  • 1
    You can configure custom serialization for a certain property-type, or for the entire object-type in NLog using `RegisterObjectTransformation`. See also: https://github.com/NLog/NLog/wiki/How-to-use-structured-logging#transform-captured-properties – Rolf Kristensen Feb 03 '22 at 18:55
  • You're up there with Jon Skeet for me, personally. Thanks @RolfKristensen – user15716642 Feb 04 '22 at 06:03

0 Answers0