destructurama / attributed

Use attributes to control how complex types are logged to Serilog.
Apache License 2.0
263 stars 32 forks source link

LogMasked for specific sink #52

Closed merodriguezblanco closed 8 months ago

merodriguezblanco commented 3 years ago

Hi there, thanks for this amazing library!

I was wondering how I can configure it so that I can mask attributes only for a specific sink. My log configuration is set up to write to console and to file (via the appsettings.json). However, I need to mask the attributes only when logging to file, but not when logging to the console.

I would appreciate any suggestion for this.

sungam3r commented 2 years ago

Attributes as well as destructuring policy work for your logged objects to construct LogEvent that will be passed to configured sinks. So there is no direct relations between attributes you are talking about and sinks. You may try to create different loggers from different instances of LoggerConfiguration. Something like appsettingsForFile.json and appSettingsForConsole.json and read them separately.

merodriguezblanco commented 2 years ago

@sungam3r thanks for the response. I'm not sure I follow. My plan is to be able to log certain attributes to file but mask them when logging to console (using serilog + destructurama). I wasn't able to do that using LogMasked because this always mask the attribute regardless of logging to file or console. I'm using appsettings.json to configure where to write to and defining the templates to log.

sungam3r commented 2 years ago

because this always mask the attribute regardless of logging to file or console

Yes. This is by design. That is the thing I was talking about. Serilog works like this:

  1. Parses initial message and builds message template applying destructuring policies, enrichers, etc.
  2. Create LogEvent with current time, parsed template and other stuff.
  3. Filters by level, properties. etc.
  4. Dispatch event to all configured sinks.

So there is only one single message (event) for all sinks. You can achieve what you want with some hacks around Serilog design, but I would not try to describe them.

github-actions[bot] commented 8 months ago

This issue was marked as stale since it has not been active for a long time

sungam3r commented 8 months ago

Closed as answered.