public void End(Action <BlockLoggerParams>?fillResultText) { if (!isLoggingEnabled || endWasCalled) { return; } endWasCalled = true; string?results = null; if (fillResultText != null && log != null) { var bp = new BlockLoggerParams(log); fillResultText(bp); results = bp.Text; } string baseMsg = String.Format("Finished method: '{0}'", blockName); if (logMessage != null) { if (results != null) { logMessage(baseMsg + " with results: " + results); } else { logMessage(baseMsg); } } }
internal BlockLogger(Log log, LogSeverity severity, string?blockName, Action <BlockLoggerParams>?fillParams, int callerLevel = 2) { isLoggingEnabled = GetIsLoggingEnabled(log, severity); if (!isLoggingEnabled) { return; } this.log = log; this.logMessage = GetLogMessageMethod(log, severity); this.blockName = blockName ?? (new StackFrame(callerLevel, false)?.GetMethod()?.Name ?? "Block name not found."); this.fillResults = null; //Log the start string baseMessage = String.Format("Entered method: '{0}'", this.blockName); if (fillParams != null) { var bp = new BlockLoggerParams(log); fillParams(bp); baseMessage += " with parameters: " + bp.Text; } logMessage(baseMessage); }