Endpoint Name from IEndpointInstance


We’re looking to email an admin if there is a critical error on an endpoint. In OnCriticalError(ICriticalErrorContext context) we wanted to get the endpoint name for our email message (e.g. ‘endpoint1 has crashed’). I can’t seem to find any documentation on how to get the endpoint name from the instance of IEndpointInstance that we have access to in the ProgramService class.


(Andreas Öhlund) #2

The endpoint instance doesn’t currently have the name available to it but you should be able to do the following:

    var endpointName = "MyEndpoint";
    var endpointConfig = new EndpointConfiguration(endpointName);

    endpointConfig.DefineCriticalErrorAction(c => MyCriticalActionHandler(endpointName, c));

    //or if you don't have access to the name, eg when using the NSB host
    endpointConfig.DefineCriticalErrorAction(c => MyCriticalActionHandler(endpointConfig.GetSettings().EndpointName(), c));

static Task MyCriticalActionHandler(string endpointName, ICriticalErrorContext context)
    //send email that includes endpointName

    //decide what to do, in this example Stop the endpoint
    return context.Stop();

Does this work for you?




At that point I can just define the string at the class level and access it directly from the OnCriticalError class. Maybe you guys will add it one day to the endpointinstance.

(Andreas Öhlund) #4

Yes that would work as well :+1:

I’ll bring the addition of the name on the instance up with the team.