jhipster-dotnetcore icon indicating copy to clipboard operation
jhipster-dotnetcore copied to clipboard

LoggerNameEnricher with generics

Open enzo-ae opened this issue 2 years ago • 1 comments

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)

enzo-ae avatar Jun 09 '22 16:06 enzo-ae

i understand if your solution is better you can create a PR here => https://github.com/jhipster/jhipster-net/blob/930dfba8ed354bbd514c601b12642620a119ae22/src/JHipsterNet.Web/Logging/LoggerNameEnricher.cs

nicolas63 avatar Jun 16 '22 13:06 nicolas63