当前位置: 首页>>代码示例>>C#>>正文


C# TraceEventType.IsValid方法代码示例

本文整理汇总了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);
      }
    }
开发者ID:howitzer-industries,项目名称:raygun.diagnostics,代码行数:71,代码来源:RaygunTraceListener.cs

示例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);
      }
    }
开发者ID:howitzer-industries,项目名称:raygun.diagnostics,代码行数:27,代码来源:RaygunTraceListener.cs


注:本文中的TraceEventType.IsValid方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。