public bool Log(LogLevel logLevel, Func <string> messageFunc, Exception exception, params object[] formatParameters) { if (messageFunc == null) { return(true); } messageFunc = LogMessageFormatter.SimulateStructuredLogging(messageFunc, formatParameters); _logWriteDelegate(ToLogMessageSeverity(logLevel), LogSystem, _skipLevel, exception, true, 0, null, _category, null, messageFunc.Invoke()); return(true); }
public bool Log(LogLevel logLevel, Func <string> messageFunc, Exception exception, params object[] formatParameters) { if (!Initialized.Value) { throw new LibLogException(ErrorInitializingProvider, s_initializeException); } if (messageFunc == null) { return(IsLogLevelEnable(logLevel)); } if (s_logEventInfoFact != null) { if (IsLogLevelEnable(logLevel)) { var formatMessage = messageFunc(); if (!s_structuredLoggingEnabled) { IEnumerable <string> _; formatMessage = LogMessageFormatter.FormatStructuredMessage(formatMessage, formatParameters, out _); formatParameters = null; // Has been formatted, no need for parameters } var callsiteLoggerType = typeof(NLogLogger); // Callsite HACK - Extract the callsite-logger-type from the messageFunc var methodType = messageFunc.Method.DeclaringType; if (methodType == typeof(LogExtensions) || methodType != null && methodType.DeclaringType == typeof(LogExtensions)) { callsiteLoggerType = typeof(LogExtensions); } else if (methodType == typeof(LoggerExecutionWrapper) || methodType != null && methodType.DeclaringType == typeof(LoggerExecutionWrapper)) { callsiteLoggerType = typeof(LoggerExecutionWrapper); } var nlogLevel = TranslateLevel(logLevel); var nlogEvent = s_logEventInfoFact(s_loggerNameDelegate(_logger), nlogLevel, formatMessage, formatParameters, exception); s_logEventDelegate(_logger, callsiteLoggerType, nlogEvent); return(true); } return(false); } messageFunc = LogMessageFormatter.SimulateStructuredLogging(messageFunc, formatParameters); if (exception != null) { return(LogException(logLevel, messageFunc, exception)); } switch (logLevel) { case LogLevel.Debug: if (s_isDebugEnabledDelegate(_logger)) { s_debugDelegate(_logger, messageFunc()); return(true); } break; case LogLevel.Info: if (s_isInfoEnabledDelegate(_logger)) { s_infoDelegate(_logger, messageFunc()); return(true); } break; case LogLevel.Warn: if (s_isWarnEnabledDelegate(_logger)) { s_warnDelegate(_logger, messageFunc()); return(true); } break; case LogLevel.Error: if (s_isErrorEnabledDelegate(_logger)) { s_errorDelegate(_logger, messageFunc()); return(true); } break; case LogLevel.Fatal: if (s_isFatalEnabledDelegate(_logger)) { s_fatalDelegate(_logger, messageFunc()); return(true); } break; default: if (s_isTraceEnabledDelegate(_logger)) { s_traceDelegate(_logger, messageFunc()); return(true); } break; } return(false); }