Sometimes during debugging you just want everything. So I’ve gone through the docs, and some various open source code examples of servicestack error handlers, and I’ve tried to make sure I’ve got a logger (I’m using serilog) to handle all the error cases.
This is from Configure.AppHost.cs
and where I’ve expanded the Configure
method to add my error handlers based on what I’ve seen other people doing. (Since there does appear to be some flexibility with where you can attach these, I went with the AppHost config.)
public override void Configure(Container container)
{
Plugins.Add(new SharpPagesFeature());
base.SetConfig(new HostConfig
{
UseSameSiteCookies = true,
DebugMode = AppSettings.Get(nameof(HostConfig.DebugMode), false)
});
this.ServiceExceptionHandlers.Add((httpReq, request, exception) =>
{
Serilog.Log.Error(exception, "ServiceStack ServiceExceptionHandlers Logger");
return null;
});
this.GatewayExceptionHandlers.Add((httpReq, request, exception) =>
{
Serilog.Log.Error(exception, "ServiceStack GatewayExceptionHandlers Logger");
});
this.UncaughtExceptionHandlers.Add((req, res, operationName, exception) =>
{
Serilog.Log.Error(exception, "ServiceStack UncaughtExceptionHandler Logger");
});
}
Have I set these up right? Do I also need the async ones? Are there any other handlers I should be adding to?
Any suggested improvements to this?