使用 ServiceStack,在两个地方实现异常处理/日志记录很重要:
每个里面
ServiceRunner<T>
。public class MyServiceRunner<T> : ServiceRunner<T> { public override object HandleException(IRequestContext requestContext, T request, Exception ex) { // Implement your exception handling/logging here. // T request is your request DTO. } }
在 AppHost 内部,以便您可以处理服务之外发生的未处理异常。
public override void Configure(Container container) { ExceptionHandler = (req, res, operationName, ex) => { //Handle Unhandled Exceptions occurring outside of Services //E.g. Exceptions during Request binding or in filters: } }
我的问题:
- 在#1 中,您可以轻松访问请求 DTO(即用于记录目的)。
- 在处理服务之外发生的异常时,我是否可以访问请求 DTO(或等效的请求有效负载)?