In contrast to the previous SmartInspect releases, I’d like to introduce some of the features for the upcoming release directly after implementing them rather than writing a cumulative preview one or two weeks before the actual release.
Let’s begin with a cool new feature of the SmartInspect libraries – the filter event. In contrast to the other events in the SmartInspect libraries, the filter event is fired before a packet is being logged. This means, with the filter event you can now influence the logging behavior in a way that was not possible with earlier SmartInspect versions. Its intended primary usage is canceling the logging of packets based on certain conditions, hence the name ‘filter’ event. I think this is best explained with an example:
using Gurock.SmartInspect; public class Program { static void Main(string[] args) { SiAuto.Si.Enabled = true; // Register an event handler for the Filter event SiAuto.Si.Filter += new FilterEventHandler(EventHandler); // The second message will be canceled and not // be logged. SiAuto.Main.LogMessage(”Message”); SiAuto.Main.LogMessage(”Cancel Me”); } static void EventHandler(object sender, FilterEventArgs args) { // Is the supplied packet a Log Entry? LogEntry logEntry = args.Packet as LogEntry; if (logEntry != null) { if (logEntry.Title.Equals(”Cancel Me“)) { args.Cancel = true; } } } }
As you can see, the usage of the filter event is pretty straightforward. The event handlers receive a FilterEventArgs argument which provides the packet that is about to be logged and offers the possibility of filtering it out. In the example, we filter out or cancel all packets which are of type LogEntry and have a title of “Cancel Me”. The filter event is a simple, yet powerful way to filter out packets.

Recent Comments