コード例 #1
0
ファイル: DnnLogging.cs プロジェクト: valadas/2sxc
 private static void AttachDnnStateIfPossible(DnnContextOld 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 */ }
 }
コード例 #2
0
ファイル: DnnLogging.cs プロジェクト: valadas/2sxc
        public static void LogToDnn(string key, string message, ILog log = null, DnnContextOld 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");
            }
        }