Пример #1
0
        protected override void OnTraceReceived(TraceMessage message)
        {
            try
            {
                object syncRoot = _lockTable[_filename];

                lock (syncRoot)
                {
                    using (FileStream fileStream = new FileStream(_filename, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read))
                    {
                        fileStream.Seek(fileStream.Length, SeekOrigin.Begin);

                        using(StreamWriter writer = new StreamWriter(fileStream))
                        {
                            writer.WriteLine(message);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Dispose(true);
                Tracer.Error(e);
            }
        }
Пример #2
0
        private void OnTraceReceived(TraceMessageEventArgs e)
        {
            TraceMessage message = e.TraceMessage;

            if (TraceLevel.HasValue && Tracer.TraceLevel < message.Type)
            {
                return;
            }

            if (TraceLevel.HasValue && message.Type < TraceLevel)
            {
                return;
            }

            OnTraceReceived(message);
        }
        protected override void OnTraceReceived(TraceMessage message)
        {
            ConsoleColor color = ConsoleColor.Gray;

            switch(message.Type)
            {
                case TraceLevels.Info: color = ConsoleColor.White; break;
                case TraceLevels.Warning: color = ConsoleColor.Yellow; break;
                case TraceLevels.Error:
                case TraceLevels.Fatal: color = ConsoleColor.Red; break;
                default: break;
            }

            ConsoleHelper.PushColor(color);
            Console.WriteLine(message);
            ConsoleHelper.PopColor();
        }
Пример #4
0
        public static void Trace(TraceLevels type, string message, params object[] args)
        {
            lock (_syncRoot)
            {
                if (TraceReceived != null)
                {
                    if (args.Length > 0)
                    {
                        message = string.Format(message, args);
                    }

                    TraceMessage traceMessage =
                        new TraceMessage(type, DateTime.UtcNow, message,
                                         string.IsNullOrEmpty(Thread.CurrentThread.Name) ? Thread.CurrentThread.ManagedThreadId.ToString() : Thread.CurrentThread.Name);

                    TraceReceived(new TraceMessageEventArgs(traceMessage));
                }
            }
        }
Пример #5
0
        protected override void OnTraceReceived(TraceMessage message)
        {
            ConsoleColor color = ConsoleColor.Gray;

            switch (message.Type)
            {
            case TraceLevels.Info: color = ConsoleColor.White; break;

            case TraceLevels.Warning: color = ConsoleColor.Yellow; break;

            case TraceLevels.Error:
            case TraceLevels.Fatal: color = ConsoleColor.Red; break;

            default: break;
            }

            ConsoleHelper.PushColor(color);
            Console.WriteLine(message);
            ConsoleHelper.PopColor();
        }
 protected override void OnTraceReceived(TraceMessage message)
 {
 }
Пример #7
0
 protected override void OnTraceReceived(TraceMessage message)
 {
     System.Diagnostics.Debug.WriteLine(message);
 }
Пример #8
0
 protected override void OnTraceReceived(TraceMessage message)
 {
     System.Diagnostics.Debug.WriteLine(message);
 }
Пример #9
0
        public TraceMessageEventArgs(TraceMessage traceMessage)
        {
            Asserter.AssertIsNotNull(traceMessage, "traceMessage");

            TraceMessage = traceMessage;
        }
Пример #10
0
 protected abstract void OnTraceReceived(TraceMessage message);
Пример #11
0
 protected abstract void OnTraceReceived(TraceMessage message);
Пример #12
0
 protected override void OnTraceReceived(TraceMessage message)
 {
 }
        public TraceMessageEventArgs(TraceMessage traceMessage)
        {
            Asserter.AssertIsNotNull(traceMessage, "traceMessage");

            TraceMessage = traceMessage;
        }
Пример #14
0
        public static void Trace(TraceLevels type, string message, params object[] args)
        {
            lock (_syncRoot)
            {
                if (TraceReceived != null)
                {
                    if(args.Length > 0)
                    {
                        message = string.Format(message, args);
                    }

                    TraceMessage traceMessage =
                        new TraceMessage(type, DateTime.UtcNow, message,
                            string.IsNullOrEmpty(Thread.CurrentThread.Name) ? Thread.CurrentThread.ManagedThreadId.ToString() : Thread.CurrentThread.Name);

                    TraceReceived(new TraceMessageEventArgs(traceMessage));
                }
            }
        }