Example #1
0
 static Logger()
 {
     string str = null;
     try
     {
         str = ConfigurationSettings.AppSettings[LEVEL_PARAM];
     }
     catch (Exception exception)
     {
         Console.WriteLine("WARN: Failure reading configuration file: " + exception.Message);
     }
     if (str != null)
     {
         globalLevel = Level.GetLevel(str);
         if (globalLevel == null)
         {
             try
             {
                 EnterpriseDT.Util.Debug.LogLevel level = (EnterpriseDT.Util.Debug.LogLevel) Enum.Parse(typeof(EnterpriseDT.Util.Debug.LogLevel), str, true);
                 globalLevel = Level.GetLevel(level);
             }
             catch (Exception)
             {
             }
         }
     }
     if (globalLevel == null)
     {
         globalLevel = Level.OFF;
         if (str != null)
         {
             Console.Out.WriteLine("WARN: '" + LEVEL_PARAM + "' configuration property invalid. Unable to parse '" + str + "' - logging switched off");
         }
     }
 }
Example #2
0
		internal LogMessageEventArgs(string loggerName, Level level, string text, params object[] args)
		{
			this.loggerName = loggerName;
			this.level = level;
			this.text = text;
			this.args = args;
			if (args != null && args.Length == 1 && args[0] is Exception)
			{
				this.e = (Exception)args[0];
			}
		}
Example #3
0
 /// <summary> Determine the logging level</summary>
 static Logger()
 {
     {
         string level = ConfigurationSettings.AppSettings["edtftp.log.level"];
         if (level != null)
             globalLevel = Level.GetLevel(level);
         else {
             globalLevel = Level.OFF;
             System.Console.Out.WriteLine("WARNING: 'edtftp.log.level' not found - logging switched off");
         }
     }
 }
Example #4
0
 /// <summary> 
 /// Log a message to our logging system
 /// </summary>
 /// <param name="level">    log level
 /// </param>
 /// <param name="message">  message to log
 /// </param>
 /// <param name="t">        throwable object
 /// </param>
 private void OurLog(Level level, string message, Exception t)
 {
     ts = DateTime.Now;
     string stamp = ts.ToString(format, CultureInfo.CurrentCulture.DateTimeFormat);
     System.Text.StringBuilder buf = new System.Text.StringBuilder(level.ToString());
     buf.Append(" [").Append(clazz).Append("] ").Append(stamp).Append(" : ").Append(message);
     if (appenders.Count == 0)
     {
         // by default to stdout
         System.Console.Out.WriteLine(buf.ToString());
         if (t != null)
         {
             System.Console.Out.WriteLine(t.StackTrace);
         }
     }
     else
     {
         for (int i = 0; i < appenders.Count; i++)
         {
             Appender a = (Appender) appenders[i];
             a.Log(buf.ToString());
             if (t != null)
             {
                 a.Log(t);
             }
         }
     }
 }
Example #5
0
 /// <summary> Log a message 
 /// 
 /// </summary>
 /// <param name="level">    log level
 /// </param>
 /// <param name="message">  message to log
 /// </param>
 /// <param name="t">        throwable object
 /// </param>
 public virtual void Log(Level level, string message, Exception t)
 {
     if (globalLevel.IsGreaterOrEqual(level))
         OurLog(level, message, t);
 }
Example #6
0
 /// <summary> Is logging enabled for the supplied level?
 /// 
 /// </summary>
 /// <param name="level">  level to test for
 /// </param>
 /// <returns> true   if enabled
 /// </returns>
 public virtual bool IsEnabledFor(Level level)
 {
     if (globalLevel.IsGreaterOrEqual(level))
         return true;
     return false;
 }
Example #7
0
		public void LogObject(Level level, string prefix, object obj)
		{
			if (this.IsEnabledFor(level))
			{
				if (obj == null)
				{
					this.Log(level, prefix + "(null)", null);
				}
				obj.GetType();
				bool flag = true;
				PropertyInfo[] properties = obj.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				PropertyInfo[] array = properties;
				for (int i = 0; i < array.Length; i++)
				{
					PropertyInfo p = array[i];
					if (this.RequiresLongFormat(p, obj))
					{
						flag = false;
						break;
					}
				}
				StringBuilder stringBuilder = new StringBuilder();
				PropertyInfo[] array2 = properties;
				for (int j = 0; j < array2.Length; j++)
				{
					PropertyInfo propertyInfo = array2[j];
					object value = propertyInfo.GetValue(obj, null);
					if (stringBuilder.Length > 0)
					{
						stringBuilder.Append(flag ? ", " : "\n  ");
					}
					stringBuilder.Append(propertyInfo.Name).Append("=");
					this.DumpValue(value, stringBuilder, "    ");
				}
				this.Log(level, prefix + stringBuilder, null);
			}
		}
Example #8
0
		static Logger()
		{
			Logger.format = "d MMM yyyy HH:mm:ss.fff";
			Logger.LEVEL_PARAM = "edtftp.log.level";
			Logger.loggers = Hashtable.Synchronized(new Hashtable(10));
			Logger.appenders = ArrayList.Synchronized(new ArrayList(2));
			Logger.showClassNames = true;
			Logger.showTimestamp = true;
			Logger.threadTags = new Dictionary<int, ILogTag>();
			Logger.mainFileAppender = null;
			Logger.mainConsoleAppender = null;
			Logger.mainTraceAppender = null;
			Logger.globalLevel = null;
			string text = null;
			try
			{
				text = ConfigurationSettings.AppSettings[Logger.LEVEL_PARAM];
			}
			catch (Exception ex)
			{
				Console.WriteLine("WARN: Failure reading configuration file: " + ex.Message);
			}
			if (text != null)
			{
				Logger.globalLevel = Level.GetLevel(text);
				if (Logger.globalLevel == null)
				{
					try
					{
						LogLevel level = (LogLevel)Enum.Parse(typeof(LogLevel), text, true);
						Logger.globalLevel = Level.GetLevel(level);
					}
					catch (Exception)
					{
					}
				}
			}
			if (Logger.globalLevel == null)
			{
				Logger.globalLevel = Level.OFF;
				if (text != null)
				{
					Console.Out.WriteLine(string.Concat(new string[]
					{
						"WARN: '",
						Logger.LEVEL_PARAM,
						"' configuration property invalid. Unable to parse '",
						text,
						"' - logging switched off"
					}));
				}
			}
		}
Example #9
0
		public virtual bool IsEnabledFor(Level level)
		{
			if (Logger.globalLevel.IsGreaterOrEqual(level))
			{
				return true;
			}
			lock (Logger.appenders.SyncRoot)
			{
				foreach (Appender appender in Logger.appenders)
				{
					if (appender is CustomLogLevelAppender)
					{
						CustomLogLevelAppender customLogLevelAppender = (CustomLogLevelAppender)appender;
						if (customLogLevelAppender.CurrentLevel.IsGreaterOrEqual(level))
						{
							return true;
						}
					}
				}
			}
			return false;
		}
Example #10
0
		private void OurLog(Level level, string message, Exception t)
		{
			this.ts = DateTime.Now;
			string value = this.ts.ToString(Logger.format, CultureInfo.CurrentCulture.DateTimeFormat);
			StringBuilder stringBuilder = new StringBuilder(level.ToString());
			if (Logger.showClassNames)
			{
				stringBuilder.Append(" [");
				stringBuilder.Append(this.clazz);
				stringBuilder.Append("]");
			}
			if (Logger.showTimestamp)
			{
				stringBuilder.Append(" ");
				stringBuilder.Append(value);
			}
			stringBuilder.Append(" : ");
			stringBuilder.Append(Logger.GetTag());
			string text = stringBuilder.ToString();
			if (message != null)
			{
				stringBuilder.Append(message);
			}
			if (t != null)
			{
				stringBuilder.Append(" : ").Append(t.GetType().FullName).Append(": ").Append(t.Message);
			}
			if (Logger.appenders.Count == 0)
			{
				Console.Out.WriteLine(stringBuilder.ToString());
				if (t != null)
				{
					if (t.StackTrace != null)
					{
						string[] array = t.StackTrace.Replace("\r", "").Split(new char[]
						{
							'\n'
						});
						for (int i = 0; i < array.Length; i++)
						{
							string str = array[i];
							this.OurLog(level, text + str, null);
						}
					}
					if (t.InnerException != null)
					{
						Console.Out.WriteLine(string.Format("{0}CAUSED BY - {1}: {2}", text, t.InnerException.GetType().FullName, t.InnerException.Message));
						if (t.InnerException.StackTrace != null)
						{
							string[] array2 = t.InnerException.StackTrace.Replace("\r", "").Split(new char[]
							{
								'\n'
							});
							for (int j = 0; j < array2.Length; j++)
							{
								string str2 = array2[j];
								this.OurLog(level, text + str2, null);
							}
							return;
						}
					}
				}
			}
			else
			{
				bool flag = Logger.globalLevel.IsGreaterOrEqual(level);
				lock (Logger.appenders.SyncRoot)
				{
					for (int k = 0; k < Logger.appenders.Count; k++)
					{
						Appender appender = (Appender)Logger.appenders[k];
						bool flag3 = false;
						if (appender is CustomLogLevelAppender)
						{
							CustomLogLevelAppender customLogLevelAppender = (CustomLogLevelAppender)appender;
							flag3 = customLogLevelAppender.CurrentLevel.IsGreaterOrEqual(level);
						}
						if (flag || flag3)
						{
							if (message != null)
							{
								appender.Log(text + message);
							}
							if (t != null)
							{
								appender.Log(text + t.GetType().FullName + ": " + t.Message);
								if (t.StackTrace != null)
								{
									string[] array3 = t.StackTrace.Replace("\r", "").Split(new char[]
									{
										'\n'
									});
									for (int l = 0; l < array3.Length; l++)
									{
										string str3 = array3[l];
										appender.Log(text + str3);
									}
								}
								if (t.InnerException != null)
								{
									appender.Log(string.Concat(new string[]
									{
										text,
										"CAUSED BY - ",
										t.InnerException.GetType().FullName,
										": ",
										t.Message
									}));
									if (t.InnerException.StackTrace != null)
									{
										string[] array4 = t.InnerException.StackTrace.Replace("\r", "").Split(new char[]
										{
											'\n'
										});
										for (int m = 0; m < array4.Length; m++)
										{
											string str4 = array4[m];
											appender.Log(text + str4);
										}
									}
								}
							}
						}
					}
				}
			}
		}
Example #11
0
		public virtual void Log(Level level, string message, params object[] args)
		{
			if (Logger.LogMessageReceived != null)
			{
				Logger.LogMessageReceived(this, new LogMessageEventArgs(this.clazz, level, message, args));
			}
			if (this.IsEnabledFor(level))
			{
				if (args != null && args.Length == 1 && args[0] is Exception)
				{
					this.OurLog(level, message, (Exception)args[0]);
					return;
				}
				if (args != null)
				{
					this.OurLog(level, string.Format(message, args), null);
					return;
				}
				this.OurLog(level, message, null);
			}
		}
Example #12
0
 public bool IsGreaterOrEqual(Level l)
 {
     return (this.level >= l.level);
 }
Example #13
0
 private void OurLog(Level level, string message, Exception t)
 {
     this.ts = DateTime.Now;
     string str = this.ts.ToString(format, CultureInfo.CurrentCulture.DateTimeFormat);
     StringBuilder builder = new StringBuilder(level.ToString());
     if (showClassNames)
     {
         builder.Append(" [");
         builder.Append(this.clazz);
         builder.Append("]");
     }
     if (showTimestamp)
     {
         builder.Append(" ");
         builder.Append(str);
     }
     builder.Append(" : ");
     string str2 = builder.ToString();
     builder.Append(message);
     if (t != null)
     {
         builder.Append(" : ").Append(t.GetType().FullName).Append(": ").Append(t.Message);
     }
     if (appenders.Count == 0)
     {
         Console.Out.WriteLine(builder.ToString());
         if (t != null)
         {
             if (t.StackTrace != null)
             {
                 foreach (string str3 in t.StackTrace.Replace("\r", "").Split(new char[] { '\n' }))
                 {
                     this.OurLog(level, str2 + str3, null);
                 }
             }
             if (t.InnerException != null)
             {
                 Console.Out.WriteLine(string.Format("{0}CAUSED BY - {1}: {2}", str2, t.InnerException.GetType().FullName, t.InnerException.Message));
                 if (t.InnerException.StackTrace != null)
                 {
                     foreach (string str4 in t.InnerException.StackTrace.Replace("\r", "").Split(new char[] { '\n' }))
                     {
                         this.OurLog(level, str2 + str4, null);
                     }
                 }
             }
         }
     }
     else
     {
         bool flag = globalLevel.IsGreaterOrEqual(level);
         lock (appenders.SyncRoot)
         {
             for (int i = 0; i < appenders.Count; i++)
             {
                 Appender appender = (Appender) appenders[i];
                 bool flag2 = false;
                 if (appender is CustomLogLevelAppender)
                 {
                     CustomLogLevelAppender appender2 = (CustomLogLevelAppender) appender;
                     flag2 = appender2.CurrentLevel.IsGreaterOrEqual(level);
                 }
                 if (flag || flag2)
                 {
                     appender.Log(str2 + message);
                     if (t != null)
                     {
                         appender.Log(str2 + t.GetType().FullName + ": " + t.Message);
                         if (t.StackTrace != null)
                         {
                             foreach (string str5 in t.StackTrace.Replace("\r", "").Split(new char[] { '\n' }))
                             {
                                 appender.Log(str2 + str5);
                             }
                         }
                         if (t.InnerException != null)
                         {
                             appender.Log(str2 + "CAUSED BY - " + t.InnerException.GetType().FullName + ": " + t.Message);
                             if (t.InnerException.StackTrace != null)
                             {
                                 foreach (string str6 in t.InnerException.StackTrace.Replace("\r", "").Split(new char[] { '\n' }))
                                 {
                                     appender.Log(str2 + str6);
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }
Example #14
0
 public void LogObject(Level level, string prefix, object obj)
 {
     if (this.IsEnabledFor(level))
     {
         if (obj == null)
         {
             this.Log(level, prefix + "(null)", null);
         }
         obj.GetType();
         bool flag = true;
         PropertyInfo[] properties = obj.GetType().GetProperties(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
         foreach (PropertyInfo info in properties)
         {
             if (this.RequiresLongFormat(info, obj))
             {
                 flag = false;
                 break;
             }
         }
         StringBuilder valueStr = new StringBuilder();
         foreach (PropertyInfo info2 in properties)
         {
             object obj2 = info2.GetValue(obj, null);
             if (valueStr.Length > 0)
             {
                 valueStr.Append(flag ? ", " : "\n  ");
             }
             valueStr.Append(info2.Name).Append("=");
             this.DumpValue(obj2, valueStr, "    ");
         }
         this.Log(level, prefix + valueStr, null);
     }
 }