Error reporting with the SDK
Published 31 December 2012
The information on this page applies to SmartAssembly Pro only.
Using the SDK code samples
You can use the SDK to:
- create a custom error reporting template (see below).
- send custom emails when you receive error reports (see below).
- attach custom files (for example, log files) to error reports (see Attaching files to error reports).
- use SQL to fetch reports from the web service (see below).
- use a transport protocol other than HTTP(S) for the error report, or to save an encrypted report to disk.
Creating a custom error reporting template
To create a custom error reporting template, adapt the sample C# code from %ProgramFiles%\Red Gate\SmartAssembly 7\SDK\Exception Reporting\, then build the assembly as a DLL.
For .NET Core applications, you should use .NET Standard version of the SDK assembly, located in: %ProgramFiles%\Red Gate\SmartAssembly 7\SDK\Exception Reporting\1 Without UI (.NET Standard)\
After you have built the DLL, change your error reporting settings in SmartAssembly to use your DLL instead of the default error reporting template.
- In the project settings window, either scroll to the Automated Error Reporting feature settings pane or, on the toolbar, click the automated error reporting icon.
- Select I want errors reported in my application.
- Select Custom Template.
- Click Browse for a Template and then select the DLL that you created.
- Enter the other information required for the Automated Error Reporting settings.
- Click Build.
When an exception is thrown, your application uses your DLL when it reports the error.
Sending custom emails when you receive error reports
If you choose to allow your customers to supply an email address with an error report, you can also set up an email response template. When you view your customer's error report, you can open the prepared response in your email client, ready to send to your customer.
File Extension
The error report requires a .saencryptedreport extension.
To set an email template, you first create a custom error report template:
Ensure that your custom template adds the email field to the exception report as a custom property, by calling
reportExceptionEventArgs.AddCustomProperty("Email", email.Text);
Open the %PROGRAMDATA%\Red Gate\SmartAssembly 7\SmartAssembly.settings file in an XML editor.
Inside the
<
Options>
node, add an<
ExceptionReports>
node and set theEmailSubject
andEmailBody
attributes, as in this example:<ExceptionReports EmailSubject="Your SampleApp error report" EmailBody="Hi,%0aI'm the developer of SampleApp. Thanks for submitting an error report for my application recently.%0aIt looks as though you found a bug, and a patch fix is now available from http://www.example.com/SampleApp-patch.exe%0aThanks again for helping to improve SampleApp!" />
- Save the SmartAssembly.settings file.
- When you build your assembly, SmartAssembly merges the custom template with your own assembly.
(Custom templates are merged even if Merge Dependencies is not enabled for the whole project.)
You can't set or read variables in the template email. We recommend you use placeholder text for product names and other information that might change. You can then replace this placeholder text in your email client, before sending the email.
Using SQL to fetch reports from the web service
You can write your own SQL query to fetch error reports from the webservice. Writing your own query allows you to integrate error reporting with your existing bug reporting systems, and can be used to email the right developer about certain types of report, for example.
We recommend that you start by adapting the sample application provided.
The sample application is a C# project included in the SDK at %ProgramFiles%\Red Gate\SmartAssembly 7\SDK\Database\SmartAssembly.Database.csproj. The project includes a reference to ..\bin\SmartAssembly.SDK.dll, but this obfuscated DLL only sends the SQL queries to the web service. The SQL queries themselves are constructed in the unobfuscated *.cs files in \Data\.
More information about the SDK samples
The supplied code samples are derived from SmartAssembly.SmartExceptionsCore.UnhandledExceptionHandler
and are based on the following four methods, which your assembly should also implement:
OnSecurityException(SecurityExceptionEventArgs)
Called when a System.Security.SecurityException is thrown.OnReportException(ReportExceptionEventArgs)
Called when any other type of exception is thrown. TheReportExceptionEventArgs
object supplied to this method encapsulates the report which is to be sent. You can therefore add files and extra parameters to this object or save and send the report within this method.OnFatalException(FatalExceptionEventArgs)
Called if the Unhandled Exception handler fails for any reason.AttachApp()
Used to attach your customised error reporting form to the application.
A call to this method is added automatically by SmartAssembly when you build an assembly with error reporting. In most cases, you do not need to edit this method.