本文整理汇总了C#中TraceEventType.IsValid方法的典型用法代码示例。如果您正苦于以下问题:C# TraceEventType.IsValid方法的具体用法?C# TraceEventType.IsValid怎么用?C# TraceEventType.IsValid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TraceEventType
的用法示例。
在下文中一共展示了TraceEventType.IsValid方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MessageFromTraceEvent
/// <summary>
/// Generates a message context from a trace event.
/// </summary>
/// <param name="eventCache">The event cache.</param>
/// <param name="source">The source.</param>
/// <param name="eventType">Type of the event.</param>
/// <param name="id">The identifier.</param>
/// <param name="message">The message.</param>
/// <param name="args">The arguments.</param>
/// <returns>MessageContext.</returns>
protected virtual MessageContext MessageFromTraceEvent(TraceEventCache eventCache, string source, TraceEventType eventType, int id, string message, params object[] args)
{
try
{
if (!eventType.IsValid())
return null;
var context = new MessageContext(new Exception(message), new List<string>(), new Dictionary<object, object>());
// get tags from the stack trace
context.Tags.AddRange(GetAttributeTags());
if (args != null)
{
var localArgs = args.Where(a => a != null).ToList();
// check the args for custom data
var custom = localArgs.FirstOrDefault(a => a is IDictionary);
if (custom != null)
{
context.Data = (IDictionary)custom;
localArgs.Remove(custom);
}
// check the args for tags
var tags = localArgs.FirstOrDefault(a => a is IList<string>);
if (tags != null)
{
context.Tags.AddRange((IList<string>)tags);
localArgs.Remove(tags);
}
// check the args for a custom exception
var error = localArgs.FirstOrDefault(a => a is Exception);
if (error != null)
{
// use the arg exception for raygun and pass the message as custom data
context.Exception = (Exception)error;
context.Data.Add("Message", message);
localArgs.Remove(error);
}
else
{
// wrap the trace message as the exception
context.Exception = new Exception(message);
}
// add the rest
var count = 0;
foreach (var leftover in localArgs)
context.Data.Add(String.Format("arg-{0}", count++), leftover);
}
return context;
}
catch (Exception e)
{
if (NotAlone()) // if someone else is listening, then trace the error
Trace.TraceError("Error on MessageFromTraceEvent in RaygunTraceListener : {0}", e.Message);
return new MessageContext(e);
}
}
示例2: MessageFromString
/// <summary>
/// Generates a message context from a trace event message
/// </summary>
/// <param name="message">The message.</param>
/// <param name="detail">The detail.</param>
/// <param name="eventType">Type of the event.</param>
/// <returns>MessageContext.</returns>
protected virtual MessageContext MessageFromString(string message, string detail = null, TraceEventType eventType = TraceEventType.Information)
{
try
{
if (!eventType.IsValid())
return null;
var tags = new List<string>();
// get tags from the stack trace
tags.AddRange(GetAttributeTags());
return new MessageContext(new Exception(string.Format("{0}. {1}", message, detail)), tags);
}
catch (Exception e)
{
if (NotAlone()) // if someone else is listening, then trace the error
Trace.TraceError("Error on MessageFromString in RaygunTraceListener : {0}", e.Message);
return new MessageContext(e);
}
}