This article is contributed. See the original author and article here.
Debug Diag involves various methods of dump collection methods that can be incorporated. In this blog we would be dealing with one such method that helps to capture crash dumps on particular exception only when it contains a specific function in its call stack.
When can you use this type of data collection?
You can use this method to capture the dumps if you are facing the below challenges:
- Your application pool recycles very frequently making it difficult to monitor the process ID for procdump command to run
- The exception being targeted can occur in other scenarios as well, hence generating a lot of false positive dumps
- We know call stack of the exception or a specific function call where the exception comes from
Steps to capture dumps for an exception occurring from specific method :
- Download the latest Debug Diagnostic Tool v2 Update 3 from https://www.microsoft.com/en-us/download/details.aspx?id=58210
- Open the Debug diag collection
- Once you open this , you will automatically be prompted with Select Rule Type wizard, if not select Add Rule from the bottom pane
- Select Crash and chose A specific IIS web application pool
- Chose the required application pool and click Next
- Click on Exceptions and got to Add Exception in the following prompt that appears
- Chose the type of exception your require and select Custom from Action Type
- Once you chose Custom you will be presented with a page to add your script
- Add the following script :
If Instr(UCASE(Debugger.Execute("!clrstack")),ucase("Your function here")) > 0 Then CreateDump "Exception",false End If
- Alternatively if you want to capture a dump for an exception that might be coming from two different methods you can use this:
If Instr(UCASE(Debugger.Execute("!clrstack")),ucase("function 1")) > 0 Then CreateDump "Exception",false ElseIf Instr(UCASE(Debugger.Execute("!clrstack")),ucase("function2 ")) > 0 Then CreateDump "Exception",false End If
- Set the Action Limit to number of dumps to be captured and hit OK
- Click Save and Close and Next in the following command prompt that appears
- Alter the Rule name and location in next prompt if required
- Chose Activate the rule now and Finish
For example, Let’s assume that we are getting the exception “System.Threading.ThreadAbortException” from method “EchoBot.dll!Microsoft.BotBuilderSamples.Controllers.BotController.PostAsync() Line 33”. In this scenario we will follow the below steps :
- Complete the steps from step 1 to step 6 as written above
- Chose the CLR Exception from the list of exceptions presented to you
- In Exception Type Equals column add : System.Threading.ThreadAbortException
- In Action Type , chose Custom from drop down menu
- In the Provide DebugDiag Script Commands For Custom Actions prompt that appears paste the following script :
If Instr(UCASE(Debugger.Execute("!clrstack")),ucase("Microsoft.BotBuilderSamples.Controllers.BotController.PostAsync")) > 0 Then CreateDump "Exception",false End If
- Follow the steps from 11 to 14 above to complete the configuration
This rule creates the dump on System.Threading.ThreadAbortException that occurs from Microsoft.BotBuilderSamples.Controllers.BotController.PostAsync.
The script indicates debug diag to capture the dump when it hits the exception you selected and involves the function call ( you mentioned in script ) in it’s call stack.
Brought to you by Dr. Ware, Microsoft Office 365 Silver Partner, Charleston SC.