public static void Publish(string message, LogLevelType logLevel, Type declaringType)
 {
     if (GlobalEvents.IsListening(logLevel))
     {
         GlobalEvents.RaiseException(null, new LogEventArgs(message, null, null, logLevel, declaringType));
     }
 }
Example #2
0
        public static void Log(LogLevelType levelType, string message, params object[] arguments)
        {
            var logMessage = levelType + "::" + DateTime.Now.ToString(CultureInfo.InvariantCulture) + "::" + String.Format(message, arguments);
            var previousForegroundColor = Console.ForegroundColor;
            var messageColor = Console.ForegroundColor;
            switch (levelType)
            {
                case LogLevelType.Warn:
                    messageColor = ConsoleColor.DarkMagenta;
                    break;
                case LogLevelType.Error:
                    messageColor = ConsoleColor.DarkRed;
                    break;
                case LogLevelType.Info:
                    messageColor = ConsoleColor.DarkGreen;
                    break;
                case LogLevelType.Debug:
                    messageColor = ConsoleColor.DarkYellow;
                    break;
            }

            if (levelType < Config.LogLevel) return;

            Console.ForegroundColor = messageColor;
            Console.WriteLine(logMessage);
            Console.ForegroundColor = previousForegroundColor;
        }
Example #3
0
 public LogMessage(object sender, string text, LogLevelType logLevel= LogLevelType.Info)
 {
     LoggerName = sender.GetType().Name;
     TimeStamp = DateTime.Now;
     LogLevel = logLevel;
     Text = text;
 }
Example #4
0
 public static void Write(string message, LogLevelType level, MPAlignerConfiguration conf=null)
 {
     if ((conf==null && level>=confLogLevel) || (conf!=null && level >= conf.logLevel && conf.logLevel!= LogLevelType.NONE)) {
         DateTime date = DateTime.Now;
         string dateStr = date.ToString("yyyy-MM-dd HH:mm:ss");
         if (level != LogLevelType.ERROR)
         {
             Console.Write("[MPAligner] [");
             Console.Write(level.ToString());
             Console.Write("] ");
             Console.Write(dateStr);
             Console.Write(" ");
             Console.WriteLine(message);
         }
         else
         {
             Console.Error.Write("[MPAligner] [");
             Console.Error.Write(level.ToString());
             Console.Error.Write("] ");
             Console.Error.Write(dateStr);
             Console.Error.Write(" ");
             Console.Error.WriteLine(message);
         }
     }
 }
 public LogEventArgs(string message, Exception ex, BaseApi api, LogLevelType logLevel, Type declaringType)
 {
     this.Exception = ex;
     this.Message = message;
     this.Api = api;
     this.LogLevel = logLevel;
     this.DateTime = DateTime.Now;
     this.DeclaringType = declaringType;
 }
Example #6
0
 public static void Log(this MessageBus msgBus, object sender, string text, LogLevelType logLevel = LogLevelType.Info)
 {
     msgBus.SendMessage(new LogMessage(sender, text, logLevel));
 }
        private static string RecordMessage(string message, LogLevelType logLevel)
        {
            var sb = new StringBuilder();

            sb.AppendLine("Time: " + DateTime.Now.ToString());
            switch (logLevel)
            {
                case LogLevelType.Warn:
                    Console.BackgroundColor = ConsoleColor.Yellow;
                    break;
                case LogLevelType.Error:
                    Console.BackgroundColor = ConsoleColor.Cyan;
                    break;
                case LogLevelType.Fatal:
                    Console.BackgroundColor = ConsoleColor.Red;
                    break;
                case LogLevelType.Debug:
                case LogLevelType.Info:
                default:

                    Console.BackgroundColor = ConsoleColor.White;
                    break;
            }

            sb.AppendLine("Message: " + message);

            string finalMessage = sb.ToString();
            Console.WriteLine(finalMessage);

            return finalMessage;
        }
 protected void Log(string text, LogLevelType logLevel = LogLevelType.Info)
 {
     MessageBus.Log(this, text, logLevel);
 }
 public static void Publish(string message, Exception ex, BaseApi api, LogLevelType logLevel)
 {
     if (GlobalEvents.IsListening(logLevel))
     {
         Type declaringType = GetDeclaringType();
         GlobalEvents.RaiseException(null, new LogEventArgs(message, ex, api, logLevel, declaringType));
     }
 }
 /// <summary>
 /// Returns true if an event is wired up the specified log level
 /// </summary>
 /// <param name="logLevel"></param>
 /// <returns></returns>
 public static bool IsListening(LogLevelType logLevel)
 {
     return GlobalEvents.IsListening(logLevel);
 }
Example #11
0
        private static string FormatText(string text, LogLevelType type)
        {
            StackFrame frame = new StackFrame(2);
            MethodBase method = frame.GetMethod();

            string ClassName = method.DeclaringType.ToString();
            int index = ClassName.LastIndexOf('.');
            if (index > 0)
                ClassName = ClassName.Substring(index + 1);

            return OutputFormat.Replace("%dt", DateTimeString)
                .Replace("%txt",text)
                .Replace("%ll", Enum.GetName(typeof(LogLevelType), type))
                .Replace("%cn", ClassName)
                .Replace("%mn", method.Name)
                .Replace("%tid", Thread.CurrentThread.ManagedThreadId.ToString());
        }
        /// <summary>
        /// Loads the configuration from a specified <c>inputFile</c>.
        /// </summary>
        /// <param name='inputFile'>
        /// Input file.
        /// </param>
        public void Load(string inputFile)
        {
            string inputStr = File.ReadAllText(inputFile,Encoding.UTF8);
            MPAlignerConfiguration conf = MPFrameworkFunctions.DeserializeString<MPAlignerConfiguration>(inputStr);

            dictConfEntryDict = conf.dictConfEntryDict;
            mosesPath = conf.mosesPath;
            translConfEntryDict = conf.translConfEntryDict;
            keepTrackOfFiles = conf.keepTrackOfFiles;
            logLevel = conf.logLevel;
            forceEnDictInterlingua = conf.forceEnDictInterlingua;
            forceEnTranslitInterlingua = conf.forceEnTranslitInterlingua;
            outputFormat = conf.outputFormat;
            excDictEntryDict = conf.excDictEntryDict;
            allowTrimmedAlignments = conf.allowTrimmedAlignments;
            stopWordListEntryDict = conf.stopWordListEntryDict;
            langPairEntryDict = conf.langPairEntryDict;
            alignmentThreads = conf.alignmentThreads;
            useMultiThreadedExecution = conf.useMultiThreadedExecution;
            printTopTrgForSrc = conf.printTopTrgForSrc;
            concLen = conf.concLen;
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="MPAligner.MPAlignerConfiguration"/> class.
 /// </summary>
 public MPAlignerConfiguration()
 {
     mosesPath = "/home/marcis/LU/moses/mosesdecoder/bin/moses";
     dictConfEntryDict = new Dictionary<string, MPAlignerConfigurationDictEntry>();
     translConfEntryDict = new Dictionary<string, MPAlignerConfigurationTranslEntry>();
     langPairEntryDict = new Dictionary<string, MPAlignerConfigurationLangPairEntry>();
     excDictEntryDict = new Dictionary<string, MPAlignerConfigurationExceptionEntry>();
     stopWordListEntryDict = new Dictionary<string, MPAlignerConfigurationStopWordListEntry>();
     allowTrimmedAlignments = false;
     outputFormat="ref_tabsep";
     keepTrackOfFiles = true;
     logLevel = LogLevelType.ERROR;
     forceEnDictInterlingua = false;
     forceEnTranslitInterlingua = false;
     alignmentThreads = 12;
     useMultiThreadedExecution = false;
     printTopTrgForSrc = false;
     concLen = 3;
 }
 protected void Log(string text, LogLevelType logLevel = LogLevelType.Info)
 {
     MessageBus.SendMessage(new LogMessage(this, text, logLevel));
 }
        /// <summary>
        ///     The is listening.
        /// </summary>
        /// <param name="logLevel">
        ///     The log level.
        /// </param>
        /// <returns>
        ///     The System.Boolean.
        /// </returns>
        internal static bool IsListening(LogLevelType logLevel)
        {
            if (Mute)
            {
                return false;
            }

            bool listening = false;

            switch (logLevel)
            {
                case LogLevelType.Verbose:
                    if (OnVerbose != null)
                    {
                        listening = true;
                    }

                    break;
                case LogLevelType.Debug:
                    if (OnDebug != null)
                    {
                        listening = true;
                    }

                    break;
                case LogLevelType.Info:
                    if (OnInfo != null)
                    {
                        listening = true;
                    }

                    break;
                case LogLevelType.Warn:
                    if (OnWarn != null)
                    {
                        listening = true;
                    }

                    break;
                case LogLevelType.Error:
                    if (OnError != null)
                    {
                        listening = true;
                    }

                    break;
                case LogLevelType.Fatal:
                    if (OnFatal != null)
                    {
                        listening = true;
                    }

                    break;
                default:
                    if (OnDebug != null)
                    {
                        listening = true;
                    }

                    break;
            }

            return listening;
        }