예제 #1
0
파일: Program.cs 프로젝트: Kuntitled/WADex
 /// <summary>
 /// Writes a colored message to stderr
 /// </summary>
 /// <param name="C">Color</param>
 /// <param name="Message">Message</param>
 /// <param name="args">Argument (for string.Format)</param>
 public static void Log(Verbosity V, string Message, params object[] args)
 {
     if (!Enum.IsDefined(V.GetType(), V))
     {
         throw new ArgumentException(string.Format("Unsupported Log Verbosity: {0}", V));
     }
     if (Verbosities.IndexOf(V) >= Verbosities.IndexOf(MinVerbosity))
     {
         ConsoleColor CC = Console.ForegroundColor;
         Console.ForegroundColor = (ConsoleColor)V;
         try
         {
             Console.Error.WriteLine(Message, args);
         }
         catch
         {
             Log(Verbosity.Error, "Unable to log message properly: {0}", Message);
         }
         if (V == Verbosity.Error)
         {
             Console.Error.WriteLine(string.Join("\n", Environment.StackTrace.Split('\n').Skip(3)));
         }
         Console.ForegroundColor = CC;
     }
 }
예제 #2
0
        public static string GetDescription(this Verbosity verbosity)
        {
            var fi         = verbosity.GetType().GetField(verbosity.ToString());
            var attributes = (DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false);

            if (attributes != null && attributes.Length > 0)
            {
                return(attributes[0].Description);
            }
            else
            {
                return(verbosity.ToString());
            }
        }