JetBrains.Profiler.SelfApi/src/Trace.cs (35 lines of code) (raw):
using System;
using System.Diagnostics;
using System.Threading;
namespace JetBrains.Profiler.SelfApi
{
/// <summary>
/// The entry point for all logging related to self-profiling.
/// </summary>
public static class Trace
{
/// <summary>
/// The current instance of <see cref="TraceSource"/> used for all logging inside self-profiling API.
/// </summary>
/// <remarks>
/// You can control trace output via App.config or via programatically added listeners, see examples below.
/// <example>
/// Redirect to console using App.config:
/// <code>
/// <system.diagnostics>
/// <sources>
/// <source name="JetBrains.Profiler.SelfApi"
/// switchName="SourceSwitch"
/// switchType="System.Diagnostics.SourceSwitch" >
/// <listeners>
/// <add name="Console" />
/// </listeners>
/// </source>
/// </sources>
/// <switches>
/// <add name="SourceSwitch" value="Verbose" />
/// </switches>
/// <sharedListeners>
/// <add name="Console"
/// type="System.Diagnostics.ConsoleTraceListener"
/// initializeData="false"/>
/// </sharedListeners>
/// <trace autoflush="true" indentsize="4">
/// <listeners>
/// <add name="Console" />
/// </listeners>
/// </trace>
/// </system.diagnostics>
/// </code>
/// </example>
/// <example>
/// <br/>
/// Redirect to console using programatically added listener:
/// <code>
/// Trace.Source.Switch = new SourceSwitch("SourceSwitch", "Verbose");
/// Trace.Source.Listeners.Add(new ConsoleTraceListener());
/// </code>
/// </example>
/// </remarks>
public static readonly TraceSource Source = new TraceSource("JetBrains.Profiler.SelfApi");
private static int _id;
/// <summary>
/// Writes message with VERBOSE level.
/// </summary>
public static void Verbose(string message)
{
Source.TraceEvent(TraceEventType.Verbose, Interlocked.Increment(ref _id), message);
}
/// <summary>
/// Writes message with VERBOSE level.
/// </summary>
public static void Verbose(string format, params object[] arguments)
{
Source.TraceEvent(TraceEventType.Verbose, Interlocked.Increment(ref _id), format, arguments);
}
/// <summary>
/// Writes message with INFO level.
/// </summary>
public static void Info(string message)
{
Source.TraceEvent(TraceEventType.Information, Interlocked.Increment(ref _id), message);
}
/// <summary>
/// Writes message with INFO level.
/// </summary>
public static void Info(string format, params object[] arguments)
{
Source.TraceEvent(TraceEventType.Information, Interlocked.Increment(ref _id), format, arguments);
}
/// <summary>
/// Writes message with ERROR level.
/// </summary>
public static void Error(string message)
{
Source.TraceEvent(TraceEventType.Error, Interlocked.Increment(ref _id), message);
}
/// <summary>
/// Writes message with ERROR level.
/// </summary>
public static void Error(string message, Exception exception)
{
Source.TraceEvent(TraceEventType.Error, Interlocked.Increment(ref _id), message + Environment.NewLine + exception);
}
}
}