Skip to content
jmoeltjen edited this page Jul 2, 2015 · 6 revisions

Adding Plugins with the Exceptionless .NET Client

A plugin is a client-side addin that is run every time you submit an event.

Index



Create a New Plugin

Specify a System.Action<EventPluginContext> or create a class that derives from IEventPlugin to create a plugin.

Every plugin is passed an EventPluginContext, which contains all the valuable contextual information that your plugin may need via the following properties:

  • Client
  • Event
  • ContextData
  • Log
  • Resolver

Plugin Example

Add System Uptime to Feature Usages

using System;
using System.Diagnostics;
using Exceptionless.Plugins;
using Exceptionless.Models;

namespace Exceptionless.SampleConsole.Plugins {
    [Priority(100)]
    public class SystemUptimePlugin : IEventPlugin {
        public void Run(EventPluginContext context) {
            // Only update feature usage events.
            if (context.Event.Type != Event.KnownTypes.FeatureUsage)
                return;

            // Get the system uptime
            using (var pc = new PerformanceCounter("System", "System Up Time")) {
                pc.NextValue();

                var uptime = TimeSpan.FromSeconds(pc.NextValue());

                // Store the system uptime as an extended property.
                context.Event.SetProperty("System Uptime", String.Format("{0} Days {1} Hours {2} Minutes {3} Seconds", uptime.Days, uptime.Hours, uptime.Minutes, uptime.Seconds));
            }
        }
    }
}

Output

Exceptionless Plugin Screenshot

Plugin Priority

The plugin priority determines the order the plugin runs (lowest to highest, then by order added). All plugins shipped with the client have a starting priority of 10 and increment by multiples of 10. For your addin to run first, give it a priority lower than 10 (e.g., 0-5). To have it run last, give it a priority higher than 100. If a priority is not specified, it defaults to 0.


Adding the Plugin to Your App

Start by calling one of the Exceptionless.ExceptionlessClient.Default.Configuration.AddPlugin() overloads. This will typically be the following:

using Exceptionless;            
ExceptionlessClient.Default.Configuration.AddPlugin<SystemUptimePlugin>();

Passing a System.Action<EventPluginContext> to AddPlugin can also be used to add a plugin. Note we specify a key so we can remove the plugin later. If you won't be removing the plugin, you can omit the first argument.

AddPlugin is passed three arguments:

  • Unique Plugin Key (to remove later, if applicable)
  • Priority
  • Action (logic)
using Exceptionless;  
ExceptionlessClient.Default.Configuration.AddPlugin("system-uptime", 100, context => {
    // Only update feature usage events.
    if (context.Event.Type != Event.KnownTypes.FeatureUsage)
        return;

    // Get the system uptime
    using (var pc = new PerformanceCounter("System", "System Up Time")) {
         pc.NextValue();
         var uptime = TimeSpan.FromSeconds(pc.NextValue());

         // Store the system uptime as an extended property.
         context.Event.SetProperty("System Uptime", String.Format("{0} Days {1} Hours {2} Minutes {3} Seconds", uptime.Days, uptime.Hours, uptime.Minutes, uptime.Seconds));

     }
});

Removing an Existing Plugin

Call one of the Exceptionless.ExceptionlessClient.Default.Configuration.RemovePlugin overloads to remove a plugin.

using Exceptionless;
ExceptionlessClient.Default.Configuration.RemovePlugin<SystemUptimePlugin>();

If it was registered via an action, you have to remove it via the key you added it with.

using Exceptionless;
ExceptionlessClient.Default.Configuration.RemovePlugin("system-uptime");