Exposes class and type information as constants in the ThisClass class using source generators powered by Roslyn, inspired by ThisAssembly.
Add the ThisClassAttribute to generate type information for a class.
[ThisClass]partialclassDemo{publicDemo(){Logger.Info($"Hello from {ThisClass.FullName}");// SampleApp.Demo}}Create class loggers without using reflection.
usingSomeNamespace;namespaceSampleApp.NLog{
...namespaceAnotherNamespace{usingSomeOtherNamespace;[ClassLoggerLazy]partialclassDemo2<T>:SomeInterface<T>whereT:SomeOtherInterface{publicstaticvoidSayHello(){Logger.Info("Hello");}[ClassLogger]internalpartialclassNestedClass:SomeInterface<SomeOtherInterface>{}}}}Looks like this behind the scenes
// <auto-generated/>
#nullable enable
namespaceSampleApp.NLog{partialclassDemo1{publicstaticpartialclassThisClass{/// <summary>/// Gets the fully qualified name of the parent class, including the namespace but not the assembly./// </summary>publicconststringFullName="SampleApp.NLog.Demo1";}}}// <auto-generated/>
#nullable enable
namespaceSampleApp.NLog{namespaceAnotherNamespace{usingSomeOtherNamespace;partialclassDemo2<T>:global::SomeNamespace.SomeInterface<T>whereT:global::SomeOtherNamespace.SomeOtherInterface{publicstaticpartialclassThisClass{/// <summary>/// Gets the fully qualified name of the parent class, including the namespace but not the assembly./// </summary>publicconststringFullName="SampleApp.NLog.AnotherNamespace.Demo2";}privatestaticglobal::NLog.Logger?__loggerLazy;privatestaticglobal::NLog.LoggerLogger=>__loggerLazy??=global::NLog.LogManager.GetLogger(ThisClass.FullName);}}}// <auto-generated/>
#nullable enable
namespaceSampleApp.NLog{namespaceAnotherNamespace{usingSomeOtherNamespace;partialclassDemo2<T>:global::SomeNamespace.SomeInterface<T>whereT:global::SomeOtherNamespace.SomeOtherInterface{partialclassNestedClass:global::SomeNamespace.SomeInterface<global::SomeOtherNamespace.SomeOtherInterface>{publicstaticpartialclassThisClass{/// <summary>/// Gets the fully qualified name of the parent class, including the namespace but not the assembly./// </summary>publicconststringFullName="SampleApp.NLog.AnotherNamespace.Demo2.NestedClass";}privatestaticreadonlyglobal::NLog.LoggerLogger=global::NLog.LogManager.GetLogger(ThisClass.FullName);}}}}