# Extensions and Tools ### Logging #### Using NLog ``` public class HomeViewModel : PortalMasterModel { private static readonly Logger _logger = LogManager.GetCurrentClassLogger(); private static readonly Logger _lmsLogger = LogManager.GetLogger("LMS"); public HomeViewModel() { // Using the class name as the name of the logger _logger.Info("Initializing HomeViewModel"); // Using a new logger instance with a property automatically added _lmsLogger.WithProperty("ActiveTab", activeTab).Info("Initializing HomeViewModel"); // Setting a property permanently on a logger _logger.SetProperty("Key", "Value"); _logger.Info("Testing EventProperties"); // Adding properties automatically in the message _logger.Info("Testing dynamic EventProperty Key={PropertyName}", "PropertyValue"); // Logging an exception _logger.WarnException("Exception", new System.Exception("Example Exception")); } } ``` ##### Example of log levels
Level | Message | Logger | Properties | Callsite | Exception |
---|---|---|---|---|---|
Info | Initializing HomeViewModel | SignifyHR.Areas.Portal.ViewModels.HomeViewModel | SignifyHR.Areas.Portal.ViewModels.HomeViewModel..ctor | ||
Info | Initializing HomeViewModel | LMS | ActiveTab=TrainingRequirements | SignifyHR.Areas.Portal.ViewModels.HomeViewModel..ctor | |
Info | Testing EventProperties | SignifyHR.Areas.Portal.ViewModels.HomeViewModel | Key=Value | SignifyHR.Areas.Portal.ViewModels.HomeViewModel..ctor | |
Info | Testing dynamic EventProperty Key="PropertyValue" | SignifyHR.Areas.Portal.ViewModels.HomeViewModel | PropertyName=PropertyValue|Key=Value | SignifyHR.Areas.Portal.ViewModels.HomeViewModel..ctor | |
Warn | Exception | SignifyHR.Areas.Portal.ViewModels.HomeViewModel | Key=Value | SignifyHR.Areas.Portal.ViewModels.HomeViewModel..ctor | System.Exception: Example Exception |
Level | Typical Use |
---|---|
Fatal | Something bad happened; application is going down |
Error | Something failed; application may or may not continue |
Warn | Something unexpected; application will continue |
Info | Normal behavior like mail sent, user updated profile etc. |
Debug | For debugging; executed query, user authenticated, session expired |
Trace | For trace debugging; begin method X, end method X |