◷ Reading Time: 2 minutes
You can also create custom channels to store the events in anywhere that you need. For instance in a database, Azure blob storage and etc.
Custom Channels
When events are raised, you can receive signals in two forms:
- Static types
- JSON formats (string)
- Free text form (via GenericTraceEvent)
Build Custom Channel
In a custom channel, you can listen to events in two ways:
Using Write and WriteLine override of TraceListener. In these methods, the custom listener receives messages in a string with JSON structure or some other free text format if GenericTraceEvent is raised.
using FlexRule.Server.Events;
class MyCustomListener : TraceListener
{
public MyCustomListener()
{
}
public override void Write(string message)
{
// message of the channel to process
}
public override void WriteLine(string message)
{
// message of the channel to process
}
}
Handle Custom Events
The channel can listen to specific events, using configuration or using your code. For using code, the DomainEvents.Register should be used to subscribe to an event. In this approach, the custom listener receives signals as .Net Types.
using FlexRule.Server.Events;
class MyCustomListener : TraceListener
{
public MyCustomListener()
{
// TYPE_OF_EVENT is the event type
// Subscribe to an event...
DomainEvents.Register(typeof(TYPE_OF_EVENT), eventHander);
// when the event occurs, the eventHandler is called.
}
private void eventHander(TYPE_OF_EVENT domainEvent)
{
// TYPE_OF_EVENT is the event type which this listener is subscribed to
}
public override void Write(string message)
{
// Do nothing
}
public override void WriteLine(string message)
{
// Do nothing
}
}
Once the custom channel is derived from TraceListener, then to register a custom channel, use the configuration on Master and/or Agents and configure them as shown below:
- Register it with a name in the channels section.
- Assign the channel to events that you want to subscribe to using the monitoring/add section.