Trace events in Optimizely Search & Navigation
Listen to tracing events raised internally in Episerver.Find assemblies. The events are raised in exceptional situations.
To receive events raised from the tracing API, you are required to register a listener by implementing the ITraceListener interface. The initialization code in Optimizely Search & Navigation searches assemblies located in the current app domain and registers the implementations, if any, that exist.
Below is an example of a trace events listener which sends an email in case of an error.
using System.Collections.Generic;
using EPiServer.Find.Tracing;
public class TestTraceListener: ITraceListener {
public TestTraceListener() {}
public virtual void Add(ITraceEvent traceEvent) {
if (traceEvent.IsError) {
MailAdmin(traceEvent.Exception, traceEvent.Message)
}
}
}
The interface of ITraceEvent
looks like this:
public interface ITraceEvent {
DateTime Timestamp {
get;
}
ITraceable Source {
get;
}
string Message {
get;
}
bool IsError {
get;
}
Exception Exception {
get;
set;
}
}
Use cases
These are some examples of how to work with event tracing.
Network issues when connecting to the index
You can use tracing to generate notifications of service exceptions. To do so, handle the following exceptions like this:
public class TestTraceListener: ITraceListener {
public virtual void Add(ITraceEvent traceEvent) {
if (traceEvent.IsError && traceEvent.Exception is typeof (ServiceException)) {
// inspect Response code to determine course of action
AlertOperations(traceEvent.Exception, traceEvent.Message, "Find Index potentially down.")
}
}
}
Document storage limit reached
This example generates a notification when the number of indexed items reaches the limit configured in your Optimizely Search & Navigation service subscription.
public class TestTraceListener: ITraceListener {
public virtual void Add(ITraceEvent traceEvent) {
if (traceEvent.IsError && traceEvent.Exception is typeof (ServiceException)) {
// if response code is 403 and message contains "Your account is not authorized to index more than"
AlertAccountMgr(traceEvent.Exception, traceEvent.Message, "limit reached for Find License")
}
}
}
Updated 8 months ago