private static void AttachDnnStateIfPossible(DnnContext dnn, LogInfo logInfo) { try { if (dnn != null) { logInfo.LogUserName = dnn.User?.DisplayName ?? "unknown"; logInfo.LogUserID = dnn.User?.UserID ?? -1; logInfo.LogPortalID = dnn.Portal.PortalId; logInfo.AddProperty("ModuleId", dnn.Module?.ModuleID.ToString() ?? "unknown"); } } catch { /* ignore */ } }
public static void LogToDnn(string key, string message, ILog log = null, DnnContext dnnContext = null, bool force = false) { if (!force) { if (!EnableLogging(GlobalConfiguration.Configuration.Properties)) { return; } } // note: this code has a lot of try/catch, to ensure that most of it works and that // it doesn't interfere with other functionality try { var logInfo = new LogInfo { LogTypeKey = EventLogController.EventLogType.ADMIN_ALERT.ToString() }; // the initial message should come first, as it's visible in the summary if (!string.IsNullOrEmpty(message)) { logInfo.AddProperty(key, message); } AttachDnnStateIfPossible(dnnContext, logInfo); log?.Entries.ForEach(e => logInfo.AddProperty(e.Source, e.Message)); new EventLogController().AddLog(logInfo); } catch { TryToReportLoggingFailure("logging"); } }