/// <summary>
        /// Logs an event to this Log-Target
        /// </summary>
        /// <param name="eventText">the event-text</param>
        /// <param name="severity">the severity of the event</param>
        /// <param name="context">provides additional information about the logging-context in which the message was generated</param>
        protected override void Log(string eventText, int severity, string context)
        {
            lock (consoleLock)
            {
                LogSeverity effective = LogEnvironment.GetClosestSeverity(severity);
                switch (effective)
                {
                case LogSeverity.Error:
                {
                    System.Console.ForegroundColor = ConsoleColor.Red;
                    break;
                }

                case LogSeverity.Warning:
                {
                    System.Console.ForegroundColor = ConsoleColor.Yellow;
                    break;
                }

                case LogSeverity.Report:
                {
                    System.Console.ForegroundColor = ConsoleColor.Gray;
                    break;
                }
                }

                System.Console.WriteLine("{0} -> {1}", context, eventText);
                System.Console.ForegroundColor = ConsoleColor.Gray;
            }
        }
Exemple #2
0
        /// <summary>
        /// Logs an event to this Log-Target
        /// </summary>
        /// <param name="eventText">the event-text</param>
        /// <param name="severity">the severity of the event</param>
        /// <param name="context">provides additional information about the logging-context in which the message was generated</param>
        protected override void Log(string eventText, int severity, string context)
        {
            lastUsage = DateTime.Now;
            string eventMessage = string.Format(@"{0:dd.MM.yyyy HH:mm:ss} {1:000} {2,10} {3} {4}
", DateTime.Now, severity, LogEnvironment.GetClosestSeverity(severity), context,
                                                eventText);

            lock (syncher)
            {
                if (currentSize > maxLogSize)
                {
                    try
                    {
                        SwitchLog();
                    }
                    catch (Exception ex)
                    {
                    }
                }

                if (innerStream == null)
                {
                    OpenStream();
                }

                WriteMessage(eventMessage);
            }
        }
        /// <summary>
        /// Logs events that were generated by any ITVComponents internal component
        /// </summary>
        /// <param name="eventText">the event-text that was generated for logging</param>
        /// <param name="severity">the severity of the event</param>
        /// <param name="context">the log-category of the event</param>
        void ILogTarget.LogEvent(string eventText, int severity, string context)
        {
            var sv       = LogEnvironment.GetClosestSeverity(severity);
            var loglevel = sv == LogSeverity.Report ? LogLevel.Information : sv == LogSeverity.Warning ? LogLevel.Warning : LogLevel.Error;
            var cat      = context ?? "ITVComponents";

            if (globalLogCfg.IsEnabled(loglevel, cat))
            {
                AddEvent(loglevel, cat, "ITVComponents-Message", eventText);
            }
        }