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

LoggerNameEnricher with generics #1053

Open
enzo-ae opened this issue Jun 9, 2022 · 1 comment
Open

LoggerNameEnricher with generics #1053

enzo-ae opened this issue Jun 9, 2022 · 1 comment
Labels
enhancement 💎 New feature or request

Comments

@enzo-ae
Copy link
Contributor

enzo-ae commented Jun 9, 2022

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)
@nicolas63
Copy link
Member

@nicolas63 nicolas63 added the enhancement 💎 New feature or request label Jun 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement 💎 New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants