Overview

We've added a new destination listener extension for ReflectInsight for sending emails. This new destination listener extension is called ReflectSoftware.Insight.Listeners.Email and allows you to send logging messages via email. This is typically done for Exceptions, Errors and Fatal messages types where you might want to be notified via email if something went wrong in your application.

Email Destination Listener Configuration

1. Download and install the ReflectInsight Viewer. You will need this installed to view your messages from the ReflectInsight Logging Extensions.

Download

2. Download the ReflectInsight Listener Extension Binaries or Source and rebuild if necessary. We already include the ReflectSoftware.Insight.Listeners.Email.dll in the libraries folder as part of the above ReflectInsight download, but we will be removing this and making it available as a NuGet package.

3. Once you have the ReflectInsight Listener Extensions, go to your project in Visual Studio and add a reference to:
  • ReflectSoftware.Insight.dll
  • ReflectSoftware.Insight.Listeners.Email.dll.
Email_Adding_Assembly.png
4. The next step is to configure your app or web configuration file and incorporate the ReflectInsight Email Listener. If you don't already have an App.config or Web.config, add it. Then open the configuration file and add a new ConfigSection as shown here:

<configuration>
  <configSections>        
    <section name="insightSettings" type="ReflectSoftware.Insight.ConfigurationHandler,ReflectSoftware.Insight"/>
  </configSections>
</configuration>
5. Now you will need to add and configure the <system.net> mail settings section in your configuration file and set the appropriate values:

<configuration>
  <system.net>
    <mailSettings>
      <smtp from="test@foo.com">
        <network host="smtpserver1" port="25" userName="username" password="secret" defaultCredentials="true" />
      </smtp>
    </mailSettings>
  </system.net>
</configuration>
6. Now you will need to add the InsightSettings section. You can get started with the following simple configuration which only includes the necessary details for this demo:

<configuration>
  <insightSettings>
    <listeners>
      <listener name="Email" type="ReflectSoftware.Insight.Listeners.ListenerEmail, ReflectSoftware.Insight.Listeners.Email"/>
    </listeners>

    <emailDetails>
      <details name="emailDetails1">
        <IsHtml>True</IsHtml>
        <toAddresses>YourEmail@Address.com</toAddresses>
        <ccAddresses></ccAddresses>
        <bccAddresses></bccAddresses>
        <subject>Application Alert: %message%</subject>
        <priority>High</priority>
        <body>
          <![CDATA[
          The following error was detected in application: '%application%'<br/><br/>          
          Message Type: %messagetype% 
			    Category:     %category% 
			    Computer:     %machine% 
			    Sender Id:    %senderid% 
			    Request Id:   %requestid% 
			    Process Id:   %processid% 
			    Thread Id:    %threadid% 
			    Domain Id:    %domainid% 
			    Application:  %application% 
			    User Domain:  %userdomain% 
			    Username:     %username%
                            Timestamp:    %time% or %time{dd-MM-yyyy hh:mm:ss.fff}%
          <b>%message%</b><br/><br/>  
          <b>%details%</b><br/><br/>
          Please call technical support: 1-888-555-5555
          ]]>
        </body>
      </details>
    </emailDetails>

    <listenerGroups active="Active">
      <group name="Active" enabled="true" maskIdentities="false">
        <destinations>
          <destination name="Email" enabled="true" filter="ErrorWarningFilter" details="Email[details=emailDetails1]"/>
        </destinations>
      </group>
    </listenerGroups>
    
    <filters>
      <filter name="ErrorWarningFilter" mode="Include">
        <method type="SendError"/>
        <method type="SendException"/>
        <method type="SendFatal"/>
      </filter>
    </filters>
  </insightSettings>
</configuration>

7. Notice the <emailDetails> section. It's in here that you define your email template. You can pass in parameters, which is shown above for example.

8. In the <listenerGroups> section, you will need to configure the Email destination and include a filter to use. The filter is defined in the <filteres> section, which you specify the messages to include or exclude from being sent to that destination. In our example, we only want to include the Error, Exception and Fatal message types. Whenever one of these messages is received, it will be delivered via email.

9. That's it, you're done!

As you can see it's very easy to get started with using the Email Listener. You can view the source and create your own listeners too.

NuGet Package

We've created a NuGet package for our Email Listener Destination extension. You can find it over on Nuget.

To install ReflectSoftware.Insight.Listeners.Email extension, run the following command in the Package Manager Console.

ReflectInsight_Email_Nuget.png

Last edited Jul 31, 2013 at 1:03 AM by RSDeveloper, version 14