TraceSourceChannel`1.cs
32 lines
| 1.2 KiB
| text/x-csharp
|
CSharpLexer
cin
|
r289 | 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() { | |||
var channel = new TraceSourceChannel(typeof(T), typeof(T).FullName); | |||
TraceRegistry.Global.Register(channel); | |||
return channel; | |||
} | |||
} | |||
} |