- Notifications
You must be signed in to change notification settings - Fork1.4k
How to create Logger for sub classes
Rolf Kristensen edited this pageMar 25, 2021 ·5 revisions
When we wish to expose the logger into sub classes the following pattern could be used.
classBaseClass{protectedBaseClass(){Log=LogManager.GetLogger(GetType().ToString());}protectedLoggerLog{get;privateset;}}classExactClass:BaseClass{publicExactClass():base(){} ...}
Alternative solution could be this:
classBaseClass{protectedvirtualLoggerLog{get{return_logger;}}privatestaticLogger_logger=LogManager.GetCurrentClassLogger();}classExactClass:BaseClass{protectedoverrideLoggerLog{get{return_logger;}}privatestaticLogger_logger=LogManager.GetCurrentClassLogger();}
-Troubleshooting Guide - See available NLog Targets and Layouts:https://nlog-project.org/config
- All targets, layouts and layout renderers
Popular: - Using NLog with NLog.config
- Using NLog with appsettings.json