• 如何在IIS中捕获指定的Exception


    前言:

    在IIS6中,对于某些没有被处理的first chance exception,其second chance exception会被aspnet CLR runtime捕获,从而在客户端页面上显示其相应的call stack等(如果customError设置的话),所以不会导致比如w3wp.exe进程的crash.

    那么,如果我们在event log看到了很多与asp.net application相关的exception,如何捕获到这些 exception,对于debug非常重要。很显然,不能简单地捕获-crash mode下的dump,因为这些exception并不会导致crash. 同时 ,也不能简单地对adplus.vbs 设置-FullOnFirst 开关, 因为这样会捕获所有first chance exception,而有些first chance exception是expected的。

    解决方法:

    解决此类的方法是设置一个config file.在config里面,指定感兴趣的specific exception,将其捕获。对于其他exception ,一律放行 :)。

    例如:以下config file指定了当捕获到System.OutofMemoryException时,生成dump;而对于其他一律不管。

    假设config file 如下:myconfig.cfg

    <Adplus>
     
    <Settings>
            
    <RunMode>crash</RunMode>
        
    </Settings>
    <precommands>
        
    <cmd>.load sos</cmd>
        
    </precommands>

    <postcommands>
    <cmd>
            sxd 
    -" !soe System.OutOfMemoryException 3;.if(@$t3==1) {.dump /mfh /u c:\\myhang\\Crash_Mode.dmp} .else {g}" clr
        
    </cmd>
    </postcommands>

    </Adplus>

    并将该config file保存至windbg安装目录下。然后启动adplus,将该config作为配置文件,命令如下:

    adplus -c myconfig.cfg -pn w3wp.exe -quiet

    这样,在w3wp.exe相应客户请求的过程中,如果有System.OutOfMemoryException抛出,则会自动生成名为Crash_Mode_*.dmp的dump 文件。

    更加具体的文章,可参考:

    http://blogs.msdn.com/tom/archive/2008/02/25/howto-capture-a-dump-on-a-specific-managed-exception.aspx

  • 相关阅读:
    Java中Comparable与Comparator的区别
    LeetCode[5] 最长的回文子串
    LeetCode[3] Longest Substring Without Repeating Characters
    LeetCode 7. Reverse Integer
    统计单词出现的次数
    System.arraycopy()和Arrays.copyOf()的区别
    SyncToy
    查看端口占用及进程号
    TCP协议
    python 的日志logging模块学习
  • 原文地址:https://www.cnblogs.com/Winston/p/1368115.html
Copyright © 2020-2023  润新知