TraceSourceChannel`1.cs
32 lines
| 1.2 KiB
| text/x-csharp
|
CSharpLexer
cin
|
r286 | using System; | |
using System.Threading; | |||
using TraceSource = System.Diagnostics.TraceSource; | |||
namespace Implab.Diagnostics { | |||
/// <summary> | |||
/// This class is used to provide a single <see cref="TraceSourceChannel"/> | |||
/// instance for the specified class in <typeparamref name="T"/> parameter. | |||
/// </summary> | |||
/// <typeparam name="T"> | |||
/// The class for which <see cref="TraceSourceChannel"/> is required. | |||
/// </typeparam> | |||
/// <remarks> | |||
/// The <see cref="TraceSourceChannel"/> instance will be created on demand | |||
/// and automatically registered in <see cref="TraceRegistry.Global"/>. | |||
/// </remarks> | |||
public static class TraceSourceChannel<T> { | |||
static Lazy<TraceSourceChannel> _traceSource = new Lazy<TraceSourceChannel>(CreateChannel, LazyThreadSafetyMode.ExecutionAndPublication); | |||
/// <summary> | |||
/// The default <see cref="TraceSourceChannel"/> instance. | |||
/// </summary> | |||
public static TraceSourceChannel Default { get { return _traceSource.Value; } } | |||
static TraceSourceChannel CreateChannel() { | |||
cin
|
r287 | var channel = new TraceSourceChannel(typeof(T), typeof(T).FullName); | |
cin
|
r286 | ||
TraceRegistry.Global.Register(channel); | |||
return channel; | |||
} | |||
} | |||
} |