如何使用ServiceStack阻止将失败的请求记录到favorite.ico

时间:2015-05-13 19:53:29

标签: servicestack

这将是第五个以favorite.ico和ServiceStack webservice框架为中心的问题。我理解未找到日志记录资源的基本原理,并且大多数变通方法使用内置未找到的处理程序,例如

appHost.CatchAllHandlers.Add((httpMethod, pathInfo, filePath) => {
   if (pathInfo.StartsWith("favicon"))
      return new NotFoundHttpHandler();
});

但这仍然会记录日志记录基础结构的异常。有没有办法充分利用两个世界,在没有找到资源时记录,而不记录对favorite.ico的请求。我必须编写代码吗?代码让我害怕:)

谢谢你, 斯蒂芬

1 个答案:

答案 0 :(得分:1)

日志记录位于NotFoundHttpHandler本身,因此为了避免日志记录,您将返回一个不记录的自定义HttpHandler,例如:

appHost.CatchAllHandlers.Add((httpMethod, pathInfo, filePath) => {
   if (pathInfo.StartsWith("/favicon"))
      return new CustomActionHandler((req,res) => {
          res.StatusCode = 404;
          res.StatusDescription = "Favicon not found";
          res.EndRequest();
      });
   return null;
});