Skip to content

LoggerNameEnricher with generics #1053

@enzo-ae

Description

@enzo-ae
Overview of the feature request

When the LoggerNameEnricher gets a generic type as context, it produces some pretty unreadable text - something like A.B.C.D.E.F.0.0.0, Culture=neutral, PublicKeyToken=null]]

I'd like to have something better readable

Motivation for or Use Case

I use generic classes that produce logs

Possible improvement
public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
{
    if (!logEvent.Properties.TryGetValue("SourceContext", out var context))
    {
        return;
    }

    string fullQualifiedClassName = context.ToString().Trim('"');
    string fullQualifiedClassNameWithoutGenerics = Regex.Replace(fullQualifiedClassName,"`1\\[\\[.*\\]\\]","<?>");
    logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty("LoggerName", GetAbbreviatedClassName(fullQualifiedClassNameWithoutGenerics, 39)));
}
Related issues or PR
  • [ x ] Checking this box is mandatory (this is just to show you read everything)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions