本文整理汇总了C#中TraceLevel类的典型用法代码示例。如果您正苦于以下问题:C# TraceLevel类的具体用法?C# TraceLevel怎么用?C# TraceLevel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TraceLevel类属于命名空间,在下文中一共展示了TraceLevel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Trace
public static void Trace(TraceLevel level, string message)
{
if (Utils.TraceListener != null && Utils.TraceListener.ShouldTrace(level))
{
Utils.TraceListener.Trace(level, message);
}
}
示例2: WriteLine
public static void WriteLine(TraceLevel level, string format, object arg1)
{
if (TraceListener != null && (level & TraceLevel) > 0)
{
TraceListener(format, arg1);
}
}
示例3: Trace
/// <summary>
/// Writes the specified trace level, message and optional exception.
/// </summary>
/// <param name="level">The <see cref="TraceLevel"/> at which to write this trace.</param>
/// <param name="message">The trace message.</param>
/// <param name="ex">The trace exception. This parameter is optional.</param>
public void Trace(TraceLevel level, string message, Exception ex)
{
if (level == TraceLevel.Off)
{
return;
}
TraceEventCache eventCache = new TraceEventCache();
TraceEventType traceEventType = GetTraceEventType(level);
foreach (TraceListener listener in DiagnosticsTrace.Listeners)
{
if (!listener.IsThreadSafe)
{
lock (listener)
{
listener.TraceEvent(eventCache, "Newtonsoft.Json", traceEventType, 0, message);
}
}
else
{
listener.TraceEvent(eventCache, "Newtonsoft.Json", traceEventType, 0, message);
}
if (DiagnosticsTrace.AutoFlush)
{
listener.Flush();
}
}
}
示例4: InvokeTextWriter
protected override void InvokeTextWriter(TraceLevel level, string source, string message, Exception ex)
{
if (MapTraceLevel(source, level) <= _traceConfig.ConsoleLevel)
{
// For Errors/Warnings we change the Console color
// for visibility
var holdColor = Console.ForegroundColor;
bool changedColor = false;
switch (level)
{
case TraceLevel.Error:
Console.ForegroundColor = ConsoleColor.Red;
changedColor = true;
break;
case TraceLevel.Warning:
Console.ForegroundColor = ConsoleColor.Yellow;
changedColor = true;
break;
}
base.InvokeTextWriter(level, source, message, ex);
if (changedColor)
{
Console.ForegroundColor = holdColor;
}
}
}
示例5: WriteLog
private static void WriteLog(TraceLevel level, String messageText)
{
try
{
EventLogEntryType LogEntryType;
switch (level)
{
case TraceLevel.Error:
LogEntryType = EventLogEntryType.Error;
break;
default:
LogEntryType = EventLogEntryType.Error;
break;
}
String LogName = "Application";
if (!EventLog.SourceExists(LogName))
{
EventLog.CreateEventSource(LogName, "BIZ");
}
EventLog eventLog = new EventLog(LogName, ".", LogName);//��־���ԵĻ���
eventLog.WriteEntry(messageText, LogEntryType);
}
catch
{
}
}
示例6: TraceMessage
protected TraceMessage(string message, TraceLevel level)
{
Message = message;
Level = level;
Timestamp = DateTime.UtcNow;
ThreadId = Thread.CurrentThread.ManagedThreadId;
}
示例7: Trace
public void Trace(HttpRequestMessage request, string category, TraceLevel level,
Action<TraceRecord> traceAction)
{
var rec = new TraceRecord(request, category, level);
traceAction(rec);
WriteTrace(rec);
}
示例8: Tracer
public Tracer(IFileSystem fileSystem, string path, TraceLevel level, IOperationLock traceLock)
{
_fileSystem = fileSystem;
_path = path;
_level = level;
_traceLock = traceLock;
}
示例9: WriteLine
/// <summary>
/// Writes the specified line to the trace log, processing the entry to
/// determine the trace level.
/// </summary>
/// <param name="message">The message to be written.</param>
public override void WriteLine( string message )
{
if( string.IsNullOrEmpty( message ) )
return;
if( this.fs == null )
return;
if( message.EndsWith( "Information: 0 : " ) )
{
this.type = TraceLevel.Info;
return;
}
else if( message.EndsWith( "Warning: 0 : " ) )
{
this.type = TraceLevel.Warning;
return;
}
else if( message.EndsWith( "Error: 0 : " ) )
{
this.type = TraceLevel.Error;
return;
}
lock( this.fs.Logs )
{
LogItem log = new LogItem( this.type, message );
this.fs.Logs.Add( log );
}
}
示例10: Trace
public void Trace(
HttpRequestMessage request,
string category,
TraceLevel level,
Action<TraceRecord> traceAction)
{
var trace = new TraceRecord(request, category, level);
traceAction(trace);
_traces.Enqueue(trace);
var context = GlobalHost.ConnectionManager.GetConnectionContext<TracePersistentConnection>();
context.Groups.Send(
TracePersistentConnection.Authenticated,
new
{
trace.RequestId,
trace.Request.RequestUri,
Status = trace.Status.ToString(),
Level = trace.Level.ToString(),
trace.Message,
trace.Category,
TimeTicks = trace.Timestamp.Ticks,
trace.Operator,
trace.Operation,
Exception = trace.Exception == null ? "" : trace.Exception.Message,
});
}
示例11: SystemTraceWriter
public SystemTraceWriter(IEventGenerator eventGenerator, ScriptSettingsManager settingsManager, TraceLevel level) : base(level)
{
_settingsManager = settingsManager;
_appName = _settingsManager.AzureWebsiteDefaultSubdomain;
_subscriptionId = Utility.GetSubscriptionId();
_eventGenerator = eventGenerator;
}
示例12: WriteLine
public static void WriteLine(string message, TraceLevel level, params object[] args)
{
if (_switch.Level < level)
return;
string dateTimeOfEvent = DateTime.Now.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss.fffffff");
string callingMethod = string.Empty;
try
{
callingMethod = new StackFrame(1).GetMethod().Name;
}
catch
{
// swallow
}
Trace.WriteLine(string.Format("{0} - {1}: {2}",
dateTimeOfEvent,
callingMethod,
args.Length == 0 ? message : string.Format(message, args)
));
}
示例13: DoTrace
static void DoTrace(TraceMessage message, TraceLevel level)
{
if (!message.CorrelationId.HasValue)
{
if (Trace.CorrelationManager.ActivityId != Guid.Empty)
{
message.CorrelationId = Trace.CorrelationManager.ActivityId;
}
}
using (var writer = new StringWriter())
{
_serializer.Serialize(writer, message);
// Can't use delegates here as all the Trace methods are [Conditional]
switch (level)
{
case TraceLevel.Info:
default:
Trace.TraceInformation(writer.ToString());
break;
case TraceLevel.Warning:
Trace.TraceWarning(writer.ToString());
break;
case TraceLevel.Error:
Trace.TraceError(writer.ToString());
break;
}
}
}
示例14: WriteLine
protected virtual void WriteLine(string context, string message, TraceLevel kind)
{
if (kind == TraceLevel.Off)
return;
if (kind != TraceLevel.Verbose)
{
try {
switch (kind)
{
case TraceLevel.Error:
Console.ForegroundColor = ConsoleColor.Red;
break;
case TraceLevel.Warning:
Console.ForegroundColor = ConsoleColor.Yellow;
break;
case TraceLevel.Info:
Console.ForegroundColor = ConsoleColor.Gray;
break;
}
Console.WriteLine("[{0}] {1} {2}", context, kind, message);
} finally {
Console.ForegroundColor = ConsoleColor.Gray;
}
}
this.LogFileWriter.WriteLine("[{0:MM/dd/yy HH:mm:ss}] [{1}] {2}: {3}", DateTime.Now, context, kind, message);
}
示例15: LogData
public LogData(DateTime dateTime, TraceLevel level, string message, string category)
{
Time = dateTime;
Level = level;
Message = message;
Category = category;
}