使用ETW记录异常的最佳方法是什么? [英] What is the best way to log exceptions using ETW?

查看:120
本文介绍了使用ETW记录异常的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有使用ETW记录异常的标准方法?

Is there a standard way to log exceptions using ETW?

据我所知,执行此操作的唯一方法是记录消息,并且可能记录内部异常消息,因为没有针对Exception类型的强类型参数.

As far as I have seen the only way to do this is to log the message and possibly the inner exception message as there is not strongly typed parameter for the Exception type.

推荐答案

使用额外的事件并在catch块中触发此事件,并将异常消息作为参数传递给事件

Use an extra Event and fire this event in the catch block and pass the exception message as a parameter to the Event

[Event(1, Message = "Application Falure: {0}", Level = EventLevel.Error, Keywords = Keywords.Diagnostic)]
public void Failure(string message) 
{ 
    if (this.IsEnabled())
    {
        this.WriteEvent(1, message); 
    }
}

使用关卡"和关键字"来控制是否要一直记录它.

Play with the Level and Keyword to control if you want to log it all the time or not.

这篇关于使用ETW记录异常的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆