Ejemplo n.º 1
0
        private static void WriteLog(LogQueueItem logQueueItem)
        {
            LogTypeConfigInfo logTypeConfigInfo = null;

            try
            {
                logTypeConfigInfo = logQueueItem.LogTypeConfigInfo;
                if (logTypeConfigInfo != null)
                {
                    LogInfo objLogInfo    = logQueueItem.LogInfo;
                    string  logProperties = objLogInfo.LogProperties.Serialize();
                    DataProvider.Instance().AddLog(objLogInfo.LogGUID,
                                                   objLogInfo.LogTypeKey,
                                                   objLogInfo.LogUserID,
                                                   objLogInfo.LogUserName,
                                                   objLogInfo.LogPortalID,
                                                   objLogInfo.LogPortalName,
                                                   objLogInfo.LogCreateDate,
                                                   objLogInfo.LogServerName,
                                                   logProperties,
                                                   Convert.ToInt32(objLogInfo.LogConfigID),
                                                   objLogInfo.Exception,
                                                   logTypeConfigInfo.EmailNotificationIsActive);
                    if (logTypeConfigInfo.EmailNotificationIsActive)
                    {
                        if (LockNotif.TryEnterWriteLock(ReaderLockTimeout))
                        {
                            try
                            {
                                if (logTypeConfigInfo.NotificationThreshold == 0)
                                {
                                    string str = logQueueItem.LogInfo.Serialize();
                                    //Mail.Mail.SendEmail(logTypeConfigInfo.MailFromAddress, logTypeConfigInfo.MailToAddress, "Event Notification", string.Format("<pre>{0}</pre>", HttpUtility.HtmlEncode(str)));
                                }
                            }
                            finally
                            {
                                LockNotif.ExitWriteLock();
                            }
                        }
                    }
                }
            }
            catch (SqlException exc)
            {
                Logger.Error(exc);
                WriteError(logTypeConfigInfo, exc, "SQL Exception", SqlUtils.TranslateSQLException(exc));
            }
            catch (Exception exc)
            {
                Logger.Error(exc);
                WriteError(logTypeConfigInfo, exc, "Unhandled Error", exc.Message);
            }
        }
Ejemplo n.º 2
0
 public virtual void UpdateLogTypeConfigInfo(LogTypeConfigInfo logTypeConfig)
 {
     LoggingProvider.Instance().UpdateLogTypeConfigInfo(logTypeConfig.ID,
                                                        logTypeConfig.LoggingIsActive,
                                                        logTypeConfig.LogTypeKey,
                                                        logTypeConfig.LogTypePortalID,
                                                        logTypeConfig.KeepMostRecent,
                                                        logTypeConfig.LogFileName,
                                                        logTypeConfig.EmailNotificationIsActive,
                                                        Convert.ToString(logTypeConfig.NotificationThreshold),
                                                        Convert.ToString(logTypeConfig.NotificationThresholdTime),
                                                        Convert.ToString((int)logTypeConfig.NotificationThresholdTimeType),
                                                        logTypeConfig.MailFromAddress,
                                                        logTypeConfig.MailToAddress);
 }
Ejemplo n.º 3
0
        public override bool LoggingIsEnabled(string logType, int portalID)
        {
            string configPortalID = portalID.ToString();

            if (portalID == -1)
            {
                configPortalID = "*";
            }
            LogTypeConfigInfo configInfo = GetLogTypeConfigInfoByKey(logType, configPortalID);

            if (configInfo == null)
            {
                return(false);
            }
            return(configInfo.LoggingIsActive);
        }
Ejemplo n.º 4
0
        private static void WriteError(LogTypeConfigInfo logTypeConfigInfo, Exception exc, string header, string message)
        {
            if (HttpContext.Current != null)
            {
                if (HttpContext.Current.IsCustomErrorEnabled)
                {
                    HttpContext.Current.AddError(exc);
                }
                else
                {
                    HttpResponse response = HttpContext.Current.Response;
                    response.StatusCode = 500;
                    HtmlUtils.WriteHeader(response, header);

                    if (logTypeConfigInfo != null)
                    {
                        HtmlUtils.WriteError(response, logTypeConfigInfo.LogFileNameWithPath, message);
                    }
                    HtmlUtils.WriteFooter(response);
                    response.End();
                }
            }
        }
Ejemplo n.º 5
0
 public void UpdateLogTypeConfigInfo(LogTypeConfigInfo logTypeConfig)
 {
     LogController.Instance.UpdateLogTypeConfigInfo(logTypeConfig);
 }
Ejemplo n.º 6
0
 public void DeleteLogTypeConfigInfo(LogTypeConfigInfo logTypeConfig)
 {
     LogController.Instance.DeleteLogTypeConfigInfo(logTypeConfig);
 }
Ejemplo n.º 7
0
 public void AddLogTypeConfigInfo(LogTypeConfigInfo logTypeConfig)
 {
     LogController.Instance.AddLogTypeConfigInfo(logTypeConfig);
 }
Ejemplo n.º 8
0
 public virtual void DeleteLogTypeConfigInfo(LogTypeConfigInfo logTypeConfig)
 {
     LoggingProvider.Instance().DeleteLogTypeConfigInfo(logTypeConfig.ID);
 }
Ejemplo n.º 9
0
        public void AddLogType(string configFile, string fallbackConfigFile)
        {
            var xmlDoc = new XmlDocument {
                XmlResolver = null
            };

            try
            {
                xmlDoc.Load(configFile);
            }
            catch (FileNotFoundException exc)
            {
                Logger.Debug(exc);
                xmlDoc.Load(fallbackConfigFile);
            }

            var logType = xmlDoc.SelectNodes("/LogConfig/LogTypes/LogType");

            if (logType != null)
            {
                foreach (XmlNode typeInfo in logType)
                {
                    if (typeInfo.Attributes != null)
                    {
                        var objLogTypeInfo = new LogTypeInfo
                        {
                            LogTypeKey          = typeInfo.Attributes["LogTypeKey"].Value,
                            LogTypeFriendlyName = typeInfo.Attributes["LogTypeFriendlyName"].Value,
                            LogTypeDescription  = typeInfo.Attributes["LogTypeDescription"].Value,
                            LogTypeCSSClass     = typeInfo.Attributes["LogTypeCSSClass"].Value,
                            LogTypeOwner        = typeInfo.Attributes["LogTypeOwner"].Value
                        };
                        AddLogType(objLogTypeInfo);
                    }
                }
            }

            var logTypeConfig = xmlDoc.SelectNodes("/LogConfig/LogTypeConfig");

            if (logTypeConfig != null)
            {
                foreach (XmlNode typeConfigInfo in logTypeConfig)
                {
                    if (typeConfigInfo.Attributes != null)
                    {
                        var logTypeConfigInfo = new LogTypeConfigInfo
                        {
                            EmailNotificationIsActive = typeConfigInfo.Attributes["EmailNotificationStatus"].Value == "On",
                            KeepMostRecent            = typeConfigInfo.Attributes["KeepMostRecent"].Value,
                            LoggingIsActive           = typeConfigInfo.Attributes["LoggingStatus"].Value == "On",
                            LogTypeKey                    = typeConfigInfo.Attributes["LogTypeKey"].Value,
                            LogTypePortalID               = typeConfigInfo.Attributes["LogTypePortalID"].Value,
                            MailFromAddress               = typeConfigInfo.Attributes["MailFromAddress"].Value,
                            MailToAddress                 = typeConfigInfo.Attributes["MailToAddress"].Value,
                            NotificationThreshold         = Convert.ToInt32(typeConfigInfo.Attributes["NotificationThreshold"].Value),
                            NotificationThresholdTime     = Convert.ToInt32(typeConfigInfo.Attributes["NotificationThresholdTime"].Value),
                            NotificationThresholdTimeType =
                                (LogTypeConfigInfo.NotificationThresholdTimeTypes)
                                Enum.Parse(typeof(LogTypeConfigInfo.NotificationThresholdTimeTypes), typeConfigInfo.Attributes["NotificationThresholdTimeType"].Value)
                        };
                        AddLogTypeConfigInfo(logTypeConfigInfo);
                    }
                }
            }
        }
Ejemplo n.º 10
0
        public void AddLog(LogInfo logInfo)
        {
            //if (Globals.Status == Globals.UpgradeStatus.Install)
            //{
            //    Logger.Info(logInfo);
            //}
            //else
            //{
            try
            {
                logInfo.LogCreateDate = DateTime.Now;
                logInfo.LogServerName = Globals.ServerName;
                if (string.IsNullOrEmpty(logInfo.LogServerName))
                {
                    logInfo.LogServerName = "NA";
                }
                if (String.IsNullOrEmpty(logInfo.LogUserName))
                {
                    logInfo.LogUserName = "";

                    //if (HttpContext.Current != null)
                    //{
                    //    if (HttpContext.Current.Request.IsAuthenticated)
                    //    {
                    //        logInfo.LogUserName = UserController.Instance.GetCurrentUserInfo().Username;
                    //    }
                    //}
                }

                //Get portal name if name isn't set
                if (logInfo.LogPortalID != Null.NullInteger && String.IsNullOrEmpty(logInfo.LogPortalName))
                {
                    //logInfo.LogPortalName = PortalController.Instance.GetPortal(logInfo.LogPortalID).PortalName;
                    logInfo.LogPortalName = "";
                }

                //Check if Log Type exists
                if (!GetLogTypeInfoDictionary().ContainsKey(logInfo.LogTypeKey))
                {
                    //Add new Log Type
                    var logType = new LogTypeInfo()
                    {
                        LogTypeKey          = logInfo.LogTypeKey,
                        LogTypeFriendlyName = logInfo.LogTypeKey,
                        LogTypeOwner        = "DotNetNuke.Logging.EventLogType",
                        LogTypeCSSClass     = "GeneralAdminOperation",
                        LogTypeDescription  = string.Empty
                    };
                    AddLogType(logType);

                    var logTypeConfigInfo = new LogTypeConfigInfo()
                    {
                        LogTypeKey                    = logInfo.LogTypeKey,
                        LogTypePortalID               = "*",
                        LoggingIsActive               = false,
                        KeepMostRecent                = "-1",
                        EmailNotificationIsActive     = false,
                        NotificationThreshold         = 1,
                        NotificationThresholdTime     = 1,
                        NotificationThresholdTimeType = LogTypeConfigInfo.NotificationThresholdTimeTypes.Seconds,
                        MailFromAddress               = String.Empty,
                        MailToAddress                 = String.Empty
                    };
                    AddLogTypeConfigInfo(logTypeConfigInfo);
                }

                if (LoggingProvider.Instance() != null)
                {
                    try
                    {
                        LoggingProvider.Instance().AddLog(logInfo);
                    }
                    catch (Exception)
                    {
                        if (Globals.Status != Globals.UpgradeStatus.Upgrade)     //this may caught exception during upgrade because old logging provider has problem in it.
                        {
                            throw;
                        }
                    }
                }
            }
            catch (Exception exc)
            {
                Logger.Error(exc);

                AddLogToFile(logInfo);
            }
            //}
        }