# HG changeset patch # User cin # Date 1397710164 -14400 # Node ID 9ce97b262a7a0e6e9ee64b45efa4c8e7417e1a57 # Parent d10034588e38cfa0c89d484914695cc6eca2b3dc# Parent e5ec543feee336b44fc00caeeab1ffcfaf557916 Слияние с default diff -r d10034588e38 -r 9ce97b262a7a Implab.v11.suo Binary file Implab.v11.suo has changed diff -r d10034588e38 -r 9ce97b262a7a Implab/Diagnostics/ConsoleTraceListener.cs --- a/Implab/Diagnostics/ConsoleTraceListener.cs Thu Apr 17 03:05:53 2014 +0400 +++ b/Implab/Diagnostics/ConsoleTraceListener.cs Thu Apr 17 08:49:24 2014 +0400 @@ -8,6 +8,16 @@ static readonly object _consoleLock = new object(); + public ConsoleTraceListener() + : base(true) { + + } + + public ConsoleTraceListener(bool local) + : base(local) { + + } + protected override void WriteEntry(TraceContext context, EventText text) { var msg = new StringBuilder(); diff -r d10034588e38 -r 9ce97b262a7a Implab/Diagnostics/TextFileListener.cs --- a/Implab/Diagnostics/TextFileListener.cs Thu Apr 17 03:05:53 2014 +0400 +++ b/Implab/Diagnostics/TextFileListener.cs Thu Apr 17 08:49:24 2014 +0400 @@ -8,7 +8,7 @@ public class TextFileListener: TextListenerBase { readonly TextWriter m_textWriter; - public TextFileListener(string fileName) { + public TextFileListener(string fileName, bool local) : base(local) { m_textWriter = File.CreateText(fileName); m_textWriter.WriteLine("LOG {0}", DateTime.Now); diff -r d10034588e38 -r 9ce97b262a7a Implab/Diagnostics/TextListenerBase.cs --- a/Implab/Diagnostics/TextListenerBase.cs Thu Apr 17 03:05:53 2014 +0400 +++ b/Implab/Diagnostics/TextListenerBase.cs Thu Apr 17 08:49:24 2014 +0400 @@ -7,9 +7,15 @@ public abstract class TextListenerBase : ServiceLocator, IEventTextFormatter, IEventTextFormatter { readonly Dictionary m_subscriptions = new Dictionary(); + readonly LogicalOperation m_boundOperation; + readonly int m_baseIndent; - protected TextListenerBase() { + protected TextListenerBase(bool local) { Register(this); + if (local) { + m_boundOperation = TraceContext.Current.CurrentOperation; + m_baseIndent = Math.Max(0, m_boundOperation.Level - 1); + } } public void Subscribe(Type eventType) { @@ -32,7 +38,12 @@ var formatter = GetService>(); EventHandler> handler = (sender, args) => { - WriteEntry((TraceContext)sender, formatter.Format((TraceContext)sender, args.Value)); + TraceContext context = (TraceContext)sender; + var text = formatter.Format(context, args.Value); + text.indent -= m_baseIndent; + + if (IsRelated(context.CurrentOperation)) + WriteEntry(context, text); }; if (m_subscriptions.ContainsKey(channel)) @@ -48,6 +59,15 @@ } } + public bool IsRelated(LogicalOperation op) { + if (m_boundOperation == null) + return true; + + while (op != m_boundOperation && op.Level > m_boundOperation.Level) + op = op.Parent; + return op == m_boundOperation; + } + public void Unsubscribe(LogChannel channel) { if (channel == null) throw new ArgumentNullException("channel"); diff -r d10034588e38 -r 9ce97b262a7a Implab/Diagnostics/TraceContext.cs --- a/Implab/Diagnostics/TraceContext.cs Thu Apr 17 03:05:53 2014 +0400 +++ b/Implab/Diagnostics/TraceContext.cs Thu Apr 17 08:49:24 2014 +0400 @@ -92,6 +92,7 @@ try { action(); } finally { + _current.EndAllOperations(); _current = old; } } @@ -156,6 +157,14 @@ } } + /// + /// Заврешает все начатые в этом контексте операции + /// + public void EndAllOperations() { + while (m_bound != m_currentOperation) + EndLogicalOperation(); + } + void LogEvent(TraceEventType type, string format, params object[] args) { LogChannel.Default.LogEvent(this, TraceEvent.Create(type, format, args)); } diff -r d10034588e38 -r 9ce97b262a7a Implab/Diagnostics/TraceEvent.cs --- a/Implab/Diagnostics/TraceEvent.cs Thu Apr 17 03:05:53 2014 +0400 +++ b/Implab/Diagnostics/TraceEvent.cs Thu Apr 17 08:49:24 2014 +0400 @@ -25,7 +25,7 @@ } public static TraceEvent Create(TraceEventType type, string format, params object[] args) { - return new TraceEvent(type, String.Format(format ?? String.Empty, args)); + return new TraceEvent(type, format == null ? String.Empty : String.Format(format, args)); } } }