Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Microsoft.Extensions.Telemetry.Abstractions #1984

Open
KennethHoff opened this issue Nov 17, 2023 · 6 comments
Open

Support for Microsoft.Extensions.Telemetry.Abstractions #1984

KennethHoff opened this issue Nov 17, 2023 · 6 comments

Comments

@KennethHoff
Copy link

Is your feature request related to a problem? Please describe.
.Net 8 released with a new telemetry abstraction library for - among other things - obfuscating values in logs.

public sealed class User
{
    public required string FirstName { get; init; }
    public required string LastName { get; init; }
    [LogPropertyIgnore] public required string Password { get; init; }
}

// Somewhere else.

var user = new User {
    FirstName = "First",
    LastName = "Last",
    Password = "hunter2",
};
_logger.LogInformation("new user created: {@NewUser}", user);

I expect the following to be logged:

[10:56:29 INF] new user created: {"FirstName": "First", "LastName": "Last", "$type": "User"}

Instead, the following is logged:

[10:56:29 INF] new user created: {"FirstName": "First", "LastName": "Last", "Password": "hunter2", "$type": "User"}

Describe the solution you'd like
Serilog removes the values annotated with LogPropertyIgnore

Additional context
It's possible I've misunderstood what the [LogPropertyIgnore] attribute is supposed to do, and it is not supposed to do what I'm asking for it to do here. If that is the case, ignore(pun intended) this issue.

@william-craven-pace
Copy link

I think you can do this already be providing a custom IDestructuringPolicy as mention here in the wiki under the Customizing the stored data section.

@bartelink
Copy link
Member

bartelink commented Nov 17, 2023

related: a question referencing some implementations of same

As for whether something like this could/should be in the box, that's another question...

@nblumhardt
Copy link
Member

nblumhardt commented Nov 17, 2023

Seems like a good question to dig into :-)

Anyone interested in putting together a Serilog.Extensions.Telemetry(Abstractions) PoC of some sort to explore how functionality in the new annotations might be applied via Serilog enrichers/destructuring policies?

@KennethHoff
Copy link
Author

This feels relevant to this conversation: dotnet/extensions#4735

@sungam3r
Copy link
Contributor

destructurama/attributed#113 allows to achive this in such way:

Log.Logger = new LoggerConfiguration()
    .Destructure.UsingAttributes(opt => opt.RespectLogPropertyIgnoreAttribute = true)
    // Other logger configuration
    .CreateLogger()

@zyofeng
Copy link

zyofeng commented May 9, 2024

Redaction support through Microsoft​.Extensions​.Compliance​.Redaction would be nice as well. Is that possible?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants