Example #1
0
 protected void GetLogMessage(List <string> Messages)
 {
     foreach (string msg in Messages)
     {
         LogMessage.Add(msg);
     }
 }
Example #2
0
 public void LogMsg(string message)
 {
     if (LogMessage == null)
     {
         LogMessage = new List <string>();
     }
     LogMessage.Add(message);
     isValid = false;
 }
Example #3
0
        private LogMessage GetBaseLogMessage(LoggingEvent loggingEvent)
        {
            var message = new LogMessage
            {
                Host        = Environment.MachineName,
                SysLogLevel = GetSyslogSeverity(loggingEvent.Level),
                TimeStamp   = loggingEvent.TimeStamp,
            };

            message.Add("LoggerName", loggingEvent.LoggerName);

            if (this.IncludeLocationInformation && loggingEvent.LocationInformation != null)
            {
                message.File = loggingEvent.LocationInformation.FileName;
                message.Line = loggingEvent.LocationInformation.LineNumber;
            }

            return(message);
        }
Example #4
0
        private LogMessage GetBaseLogMessage(LoggingEvent loggingEvent)
        {
            var message = new LogMessage
            {
                Host      = Environment.MachineName,
                Level     = GetLevelAsNumber(loggingEvent.Level),
                LevelName = loggingEvent.Level.Name,
                Time      = loggingEvent.TimeStamp
                            .ToUniversalTime()
                            .ToString("yyyy-MM-ddTHH:mm:ss.fffZ")
            };

            message.Add("loggername", loggingEvent.LoggerName);

            if (this.IncludeLocationInformation)
            {
                message.File = loggingEvent.LocationInformation.FileName;
                message.Line = loggingEvent.LocationInformation.LineNumber;
            }

            return(message);
        }
Example #5
0
 public void LogMsg(string message)
 {
     LogMessage.Add(message);
 }
Example #6
0
    /// <summary>
    /// Logs the exception.
    /// </summary>
    /// <param name="ex">The exception to log.</param>
    /// <returns>id of exception logged (-1 if log fails)</returns>
    public static long LogException(Exception ex, bool sendEmail = true)
    {
        long id = -1, lastid = -1;;

        try
        {
            while (ex != null && typeof(Exception) == typeof(HttpUnhandledException))
            {
                ex = ex.InnerException;
            }

            if (ex == null)
            {
                return(-1);
            }

            //We need to grab this value so we can email it.
            Exception origEx = ex;

            //Some temp variables to remember the IDs.
            bool   saved    = false;
            string errorMsg = string.Empty;

            //Make sure the user is one for which we want to create a log.
            string username = GetCurrentUserName(HttpContext.Current);
            if (string.IsNullOrWhiteSpace(username))
            {
                username = "******";
            }
            else
            {
                username = username.ToLower();
            }

            LogMessage    lm      = null;
            StringBuilder message = new StringBuilder();
            if (HttpContext.Current != null)
            {
                message.AppendLine(HttpContext.Current.Request.Url.ToString());
            }

            while (ex != null)
            {
                //Prepare the message to be logged to the database.
                lm         = new LogMessage();
                lm.LogType = 5;                 //exception
                if (lastid > 0)
                {
                    lm.ParentId = lastid;
                }
                lm.Username      = username;
                lm.MessageDate   = DateTime.Now.ToString();
                lm.ExceptionType = ex.GetType().ToString();
                lm.Message       = ex.Message;
                lm.StackTrace    = ex.StackTrace;
                lm.MessageSource = ex.Source;
                lm.AppVersion    = string.Empty;
                lm.Url           = HttpContext.Current != null ? HttpContext.Current.Request.Path : null;

                lastid = lm.Add(out saved, out errorMsg);
                if (id <= 0)
                {
                    id = lastid;
                }

                //Prepare the message to be emailed
                message.AppendLine(ex.GetType().ToString());
                message.AppendLine(ex.Message);
                message.AppendLine(ex.StackTrace);
                ex = ex.InnerException;
                if (ex != null)
                {
                    message.AppendLine();
                }
            }

            //email the exception if requested
            if (sendEmail)
            {
                EmailException(origEx, id);
            }
        }
        catch (Exception)
        {
        }

        return(id);
    }
Example #7
0
        private LogMessage GetBaseLogMessage(LoggingEvent loggingEvent)
        {
            var message = new LogMessage
            {
                Host = Environment.MachineName,
                SysLogLevel = GetSyslogSeverity(loggingEvent.Level),
                TimeStamp = loggingEvent.TimeStamp,
            };

            message.Add("LoggerName", loggingEvent.LoggerName);

            if (this.IncludeLocationInformation)
            {
                message.File = loggingEvent.LocationInformation.FileName;
                message.Line = loggingEvent.LocationInformation.LineNumber;
            }

            return message;
        }