private static LoggingEvent[] LogInstanceMethodHelper(ILog loggingInstance, string debugMessage, Exception exceptionMessage = null) { //if (!LogManager.GetRepository().Configured) // BasicConfigurator.Configure(); //If you need to know how to configure a repository //Use hierarchy to to get Repository and then get Root to access IAppenderAttachable var hierarchy = (Hierarchy)LogManager.GetRepository(); //Remove all appenders and setup a memory appender so that we don't write to the database var attachable = hierarchy.Root as IAppenderAttachable; //if (attachable == null) return ("IappenderAttachable is null"); attachable.RemoveAllAppenders(); var appender = new MemoryAppender(); attachable.AddAppender(appender); if (exceptionMessage == null) { EntLogger.LogDebug(loggingInstance, debugMessage); } else { EntLogger.LogException(loggingInstance, debugMessage, exceptionMessage); } var loggingEvents = appender.GetEvents(); //Cleanup attachable.RemoveAppender(appender); return(loggingEvents); }
public void VerifyLogDebugInvokedOnce() { // Arrange var moqEntLogger = new Mock <ILog>(); // Act EntLogger.LogDebug(moqEntLogger.Object, "MockDebugMessage"); // Assert moqEntLogger.Verify(log => log.Debug("MockDebugMessage"), Times.Once()); }
//Note that loggInstance is injected as a dependency of LoggingFromChildClass public void LoggingFromChildClass(ILog loggingInstance) { EntLogger.LogDebug(loggingInstance, "Entering LoggingFromChildClass"); try { throw new Exception("Test Message Text", new Exception("ChildClass Exception")); } catch (Exception ex) { EntLogger.LogException(loggingInstance, ex.Message, ex); } EntLogger.LogDebug(loggingInstance, "Exiting LoggingFromChildClass"); }
//Note that loggInstance is injected as a dependency of Logit public void Logit(ILog loggingInstance) { EntLogger.LogDebug(loggingInstance, "Entering LogIt"); try { throw new Exception("Test Message Text", new Exception("Inner Exception Text")); } catch (Exception ex) { EntLogger.LogException(loggingInstance, ex.Message, ex); } EntLogger.LogDebug(loggingInstance, "Exiting LogIt"); ChildClass childClass = new ChildClass(); childClass.LoggingFromChildClass(loggingInstance); }