Introduction
Logging in custom application is mandatory, tracing business process execution, trouble shooting and detecting errors, etc.....
But what if a critical error occured, and needs a quick action, or how would you know that something went wrong.
WMI events: you can raise WMI events to be captured by an application to act quickly (MOM for example), send an E-mail, send SMS etc......
Background
WMI:Windows Management Instrumentation (WMI) is a set of extensions to the Windows Driver Model that provides an operating system interface through whichinstrumented components provide information and notification. WMI is Microsoft's implementation of the Web-Based Enterprise Management (WBEM) and Common Information Model (CIM) standards from the Distributed Management Task Force (DMTF).
Using the code
this class is a representation for the Message that is gonna be publish.
[InstrumentationClass(InstrumentationType.Instance)]
public class InfoMessage
{
public string Message;
public string ApplicationName;
public string Guid;
public int Type;
public static InfoMessage EmptyMessage()
{
return new InfoMessage();
}
}
public class EventDetails : BaseEvent
{
public string Message;
public string ApplicationName;
public string Guid;
public int Type;
}
public class InstrumentationProvider
{
private InstrumentationProvider()
{
}
public static InfoMessage PublishMessage(string MessageText,string applicationName,MessageType Type)
{
InfoMessage Message = new InfoMessage();
Message.Message = MessageText;
Message.ApplicationName = applicationName;
Message.Guid = Guid.NewGuid().ToString();
Message.Type = (int)Type;
try
{
Instrumentation.Publish(Message);
}
catch (ManagementException)
{
return InfoMessage.EmptyMessage();
}
return Message;
}
public static void RevokeMessage(InfoMessage Message)
{
Instrumentation.Revoke(Message);
}
public static bool FireEvent(string Message,string applicationName, EventType Type)
{
EventDetails Details = new EventDetails();
Details.Message = Message;
Details.ApplicationName = applicationName;
Details.Guid = Guid.NewGuid().ToString();
Details.Type = (int)Type;
try
{
Details.Fire();
}
catch (ManagementException)
{
return false;
}
return true;
}
}
[RunInstaller(true)]
public class InstrumentationProviderInstaller : DefaultManagementProjectInstaller
{
}
Points of Interest
System.Management.Instrumentation;
History
V1.0