Beispiel #1
0
        public static void Log(string message, DebugLogLevel loggingLevel = DebugLogLevel.Trace)
        {
            if (LoggingLevel == DebugLogLevel.None)
            {
                return;
            }

            //var messageKey = message.ToUpper();
            //if (messageKey.Contains("ERROR") || messageKey.Contains("ERROR"))
            //    loggingLevel = DebugLogLevel.Error;

            //else if (messageKey.Contains("WARNING"))
            //    loggingLevel = DebugLogLevel.Warning;

            if (loggingLevel > LoggingLevel)
            {
                return;
            }

            var logTime = IsUsingLogTime ? LogTime() + " " : "";

            Debug.WriteLine(logTime + LoggingPrefix + message);

            LogToFile(LogTime() + " " + message);

            // Debug.WriteLine(LoggingPrepend + message);
        }
Beispiel #2
0
 public void Debug(string message, DebugLogLevel debugLevel)
 {
     if (debugLevel >= DebugLogLevel)
     {
         _task.BuildEngine.LogMessageEvent(new BuildMessageEventArgs(message, "", MessageSender, MessageImportance.Low));
     }
 }
Beispiel #3
0
 // on object references
 public static void DebugLog(this Exception ex, DebugLogLevel debugLogLevel = DebugLogLevel.simple) // C# 4.0: optional parameters (default parameter values)
 {
     if (debugLogLevel == DebugLogLevel.simple)
     {
         ex.Message.DebugLog();
     }
     else
     {
         ex.ToString().DebugLog();
     }
 }
Beispiel #4
0
		private static string DetailedLogMessage(string category, DebugLogLevel type, string message)
		{
			StringBuilder stringBuilder = new StringBuilder();
			DateTime now = DateTime.Now;
			stringBuilder.Append(string.Concat("[", now.ToString(), "] "));
			int managedThreadId = Thread.CurrentThread.ManagedThreadId;
			stringBuilder.Append(string.Concat(managedThreadId.ToString(), ": "));
			stringBuilder.Append(string.Concat(category, ": "));
			stringBuilder.Append(string.Concat(type.ToString(), ": "));
			stringBuilder.Append(message);
			return stringBuilder.ToString();
		}
Beispiel #5
0
        private static string DetailedLogMessage(string category, DebugLogLevel type, string message)
        {
            StringBuilder stringBuilder = new StringBuilder();
            DateTime      now           = DateTime.Now;

            stringBuilder.Append(string.Concat("[", now.ToString(), "] "));
            int managedThreadId = Thread.CurrentThread.ManagedThreadId;

            stringBuilder.Append(string.Concat(managedThreadId.ToString(), ": "));
            stringBuilder.Append(string.Concat(category, ": "));
            stringBuilder.Append(string.Concat(type.ToString(), ": "));
            stringBuilder.Append(message);
            return(stringBuilder.ToString());
        }
Beispiel #6
0
        /// <summary>
        /// 写LOG,LOG将按日期分类
        /// </summary>
        /// <param name="type">不同类别保存在不同文件里面</param>
        /// <param name="message">正文</param>
        /// <param name="url">请求地址</param>
        public static void WriteLog(string type, string message, DebugLogLevel lv, string url = "", Exception ex = null)
        {
            var      setting = GetConfig <string>("DebugLog");
            DebugLog sysDebugLog;

            Enum.TryParse <DebugLog>(setting, out sysDebugLog);

            Action writeLog = () =>
            {
                var path = HttpContext.Current.Request.MapPath($"~/Logs/{DateTime.Now:yyyy-MM-dd}/{type}.log");
                System.IO.FileInfo info = new System.IO.FileInfo(path);
                if (!info.Directory.Exists)
                {
                    info.Directory.Create();
                }
                System.IO.File.AppendAllText(path, $"{DateTime.Now:yyyy-MM-dd HH:mm:ss} {message} {url} {ex?.Source}\r\n");
            };

            switch (sysDebugLog)
            {
            case DebugLog.All:
                writeLog();
                break;

            default:
            case DebugLog.No:
                break;

            case DebugLog.Warning:
                if (lv == DebugLogLevel.Warning || lv == DebugLogLevel.Error)
                {
                    writeLog();
                }
                break;

            case DebugLog.Error:
                if (lv == DebugLogLevel.Error)
                {
                    writeLog();
                }
                break;
            }
        }
Beispiel #7
0
        static DebugLogger()
        {
            ConfigurationHandler section = (ConfigurationHandler)ConfigurationManager.GetSection("Microsoft.ActiveDirectory");

            if (section == null || section.TraceSection == null)
            {
                return;
            }
            else
            {
                TraceElement traceSection = section.TraceSection;
                DebugLogger._level = traceSection.LogLevel;
                string logFile = traceSection.LogFile;
                if (!string.IsNullOrEmpty(logFile))
                {
                    logFile = Environment.ExpandEnvironmentVariables(logFile);
                    foreach (TraceListener listener in Trace.Listeners)
                    {
                        if (listener as DefaultTraceListener == null)
                        {
                            continue;
                        }
                        ((DefaultTraceListener)listener).LogFileName = logFile;
                        break;
                    }
                }
                if (DebugLogger._level > DebugLogLevel.Off)
                {
                    StringBuilder stringBuilder = new StringBuilder();
                    DateTime      now           = DateTime.Now;
                    stringBuilder.Append(string.Concat("[", now.ToString(), "] "));
                    stringBuilder.Append(string.Concat(Process.GetCurrentProcess().ProcessName.ToString(), ": "));
                    int id = Process.GetCurrentProcess().Id;
                    stringBuilder.Append(string.Concat(id.ToString(), ": "));
                    stringBuilder.Append(string.Concat("level=", DebugLogger._level.ToString(), ": "));
                    stringBuilder.Append(string.Concat("logFile=", logFile));
                    Trace.WriteLine(null);
                    Trace.WriteLine(stringBuilder.ToString());
                }
                return;
            }
        }
Beispiel #8
0
		static DebugLogger()
		{
			ConfigurationHandler section = (ConfigurationHandler)ConfigurationManager.GetSection("Microsoft.ActiveDirectory");
			if (section == null || section.TraceSection == null)
			{
				return;
			}
			else
			{
				TraceElement traceSection = section.TraceSection;
				DebugLogger._level = traceSection.LogLevel;
				string logFile = traceSection.LogFile;
				if (!string.IsNullOrEmpty(logFile))
				{
					logFile = Environment.ExpandEnvironmentVariables(logFile);
					foreach (TraceListener listener in Trace.Listeners)
					{
						if (listener as DefaultTraceListener == null)
						{
							continue;
						}
						((DefaultTraceListener)listener).LogFileName = logFile;
						break;
					}
				}
				if (DebugLogger._level > DebugLogLevel.Off)
				{
					StringBuilder stringBuilder = new StringBuilder();
					DateTime now = DateTime.Now;
					stringBuilder.Append(string.Concat("[", now.ToString(), "] "));
					stringBuilder.Append(string.Concat(Process.GetCurrentProcess().ProcessName.ToString(), ": "));
					int id = Process.GetCurrentProcess().Id;
					stringBuilder.Append(string.Concat(id.ToString(), ": "));
					stringBuilder.Append(string.Concat("level=", DebugLogger._level.ToString(), ": "));
					stringBuilder.Append(string.Concat("logFile=", logFile));
					Trace.WriteLine(null);
					Trace.WriteLine(stringBuilder.ToString());
				}
				return;
			}
		}
Beispiel #9
0
 public void Debug(string message, DebugLogLevel debugLevel)
 {
     _weaver.InternalLogDebug(message, debugLevel);
 }
Beispiel #10
0
		private void Trace(DebugLogLevel type, string message)
		{
			if (type != DebugLogLevel.Error)
			{
				if (type != DebugLogLevel.Info)
				{
					DebugLogger.WriteLine(this._debugCategory, message);
					return;
				}
				else
				{
					DebugLogger.LogInfo(this._debugCategory, message);
					return;
				}
			}
			else
			{
				DebugLogger.LogError(this._debugCategory, message);
				return;
			}
		}
Beispiel #11
0
		private static string DetailedLogMessage(string category, DebugLogLevel type, string format, object[] args)
		{
			return DebugLogger.DetailedLogMessage(category, type, string.Format(CultureInfo.InvariantCulture, format, args));
		}
Beispiel #12
0
 private static string DetailedLogMessage(string category, DebugLogLevel type, string format, object[] args)
 {
     return(DebugLogger.DetailedLogMessage(category, type, string.Format(CultureInfo.InvariantCulture, format, args)));
 }