destructurama / attributed

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

[NotLogged] not working for record types #121

Closed DinoSourcesRex closed 3 weeks ago

DinoSourcesRex commented 3 months ago

Describe the bug Given the following record:

public record Token
{
    public string Name { get; init; }

    [NotLogged]
    public string Value { get; init; }

    public Token(string name, string value)
    {
        Name = name;
        Value = value;
    }
}

I would expect that the Value property is not logged, but it does get logged.

Simply changing the record to a class type fixes this, so I feel as though this is a bug.

Expected behavior I would expect that the attribute works on record types and correctly does not log the property.

mobilebilly commented 2 months ago

@DinoSourcesRex , I was not able to reproduce the same issue with the code below in dotnet8, Serilog 4.0.1, Serilog.Sinks.Console 6.0.0, what is your setup?


    internal class Program
    {
        static void Main(string[] args)
        {
            using var log = new LoggerConfiguration()
                .Destructure.UsingAttributes()
                .WriteTo.Console()
                .CreateLogger();

            var token = new Token("Key", "Value");

            log.Information("templated: {@token}", token);
        }
    }

    public record Token
    {
        public string Name { get; init; }

        [NotLogged]
        public string Value { get; init; }

        public Token(string name, string value)
        {
            Name = name;
            Value = value;
        }
    }
github-actions[bot] commented 1 month ago

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

DinoSourcesRex commented 3 weeks ago

@mobilebilly I'm closing this! After updating some libraries everything started to work. Thanks!