示例#1
0
文件: Log.cs 项目: lnystad/OrionFelt
        /// <summary>
        /// 
        /// </summary>
        /// <param name="level">Current logging level</param>
        /// <param name="exception">The exception that should be logged</param>
        /// <returns>Guid that identifies the error incident.</returns>
        private static Guid LogWrite(LoggingLevels level, LoggingEvent loggingEvent)
        {
            Guid incidentId = Guid.Empty;
           
            if (s_appenders != null && s_appenders.Count > 0)
            {

                foreach (ILogAppender appender in s_appenders)
                {
                    try
                    {
                        if (appender != null &&
                            appender.LoggingLevel != LoggingLevels.None &&
                            appender.LoggingLevel >= level)
                        {
                            appender.Append(level, loggingEvent);
                        }
                    }
                    catch
                    {
                        //Do nothing...
                    }
                }

            }
            else
            {
                Log.Failover.Append(level, loggingEvent);
            }
            return incidentId;
        }
示例#2
0
 public override void Append(LoggingLevels level, LoggingEvent loggingEvent)
 {
     if (loggingEvent != null)
     {
         string details = String.IsNullOrEmpty(loggingEvent.ExceptionDescription) ? "" : String.Format(CultureInfo.InvariantCulture, " - Details: {0}", loggingEvent.ExceptionDescription);
         Trace.WriteLine(String.Format(CultureInfo.InvariantCulture, "{0}{1}", loggingEvent.UserMessage, details));
     }
 }
示例#3
0
 ///// <summary>
 ///// Returns a formatted message that contains both the message and the exception details.
 ///// </summary>
 ///// <param name="message">The message to format</param>
 ///// <param name="exception">The exception to format</param>
 ///// <returns>The combined message</returns>
 public virtual string FormatMessage(LoggingLevels level, LoggingEvent loggingEvent)
 {
     if (loggingEvent == null)
     {
         throw new ArgumentNullException("loggingEvent");
     }
     if (!String.IsNullOrEmpty(loggingEvent.UserMessage) &&
         !String.IsNullOrEmpty(loggingEvent.ExceptionDescription))
     {
         return String.Format(CultureInfo.InvariantCulture,"{0} - Details: {1}", loggingEvent.UserMessage, loggingEvent.ExceptionDescription);
     }
     else if (!String.IsNullOrEmpty(loggingEvent.UserMessage))
     {
         return loggingEvent.UserMessage;
     }
     else if (!String.IsNullOrEmpty(loggingEvent.ExceptionDescription))
     {
         return loggingEvent.ExceptionDescription;
     }
     else
     {
         return loggingEvent.ToString();
     }
 }
示例#4
0
        //public abstract void WriteLine(LoggingLevels level, string message, Exception exception);

        public abstract void Append(LoggingLevels level, LoggingEvent loggingEvent);
示例#5
0
        private static void SetDefaultValues(LoggingEvent loggingEvent)
        {
            loggingEvent.ExceptionTime = DateTime.Now;
            loggingEvent.Source = System.Threading.Thread.GetDomain().FriendlyName;

            

            loggingEvent.VersionNumber = GetAssemblyVersionNumber();
        }
示例#6
0
        //public abstract void WriteLine(LoggingLevels level, string message, Exception exception);

        public abstract void Append(LoggingLevels level, LoggingEvent loggingEvent);
示例#7
0
文件: Log.cs 项目: lnystad/OrionFelt
 /// <summary>
 /// Logs an trace description with the specified logging event.
 /// </summary>
 /// <param name="loggingEvent">The logging event</param>
 public static void Trace(LoggingEvent loggingEvent)
 {
     Log.LogWrite(LoggingLevels.Trace, loggingEvent);
 }
示例#8
0
文件: Log.cs 项目: lnystad/OrionFelt
 /// <summary>
 /// Logs an information description with the specified logging event.
 /// </summary>
 /// <param name="loggingEvent">The logging event</param>
 public static void Warning(LoggingEvent loggingEvent)
 {
     Log.LogWrite(LoggingLevels.Warning, loggingEvent);
 }
示例#9
0
文件: Log.cs 项目: lnystad/OrionFelt
 /// <summary>
 /// Logs an information description with the specified logging event.
 /// </summary>
 /// <param name="loggingEvent">The logging event</param>
 public static void Info(LoggingEvent loggingEvent)
 {
     Log.LogWrite(LoggingLevels.Info, loggingEvent);
 }
示例#10
0
文件: Log.cs 项目: lnystad/OrionFelt
 /// <summary>
 /// Logs an error with the specified description.
 /// </summary>
 /// <param name="loggingEvent">The logging event</param>
 /// <returns>Guid that identifies the error incident.</returns>
 public static Guid Error(LoggingEvent loggingEvent)
 {
     return Log.LogWrite(LoggingLevels.Error, loggingEvent);
 }
示例#11
0
 public override void Append(LoggingLevels level, LoggingEvent loggingEvent)
 {
     try
     {
         lock (FileAppender.s_syncObject)
         {
             using (FileStream stream = this.PrepeareAndCreateFileStream())
             {
                 using (StreamWriter writer = new StreamWriter(stream))
                 {
                     writer.WriteLine("{0:dd.MM.yyyy HH:mm:ss} [{1,-8}]: {2}", DateTime.Now, level, this.FormatMessage(level, loggingEvent));
                     writer.Flush();
                 }
             }
         }
     }
     catch (Exception e)
     {
         Trace.WriteLine(String.Format(CultureInfo.InvariantCulture, "Exception occured when writing to logfile. Details: {0}", e.ToString()));
     }
 }