1. 新建Web API项目

  2. 配置Swagger,本项目中使用的swagger包如下

  3. Nuget安装MiniProfiler,目前最新版本是4.2.1,支持的.Net框架是4.6.1,注意不要选错

  4. 在Global.asax.cs中添加如下代码

  1. protected void Application_Start()
  2. {
  3. GlobalConfiguration.Configure(WebApiConfig.Register);
  4. MiniProfiler.Configure(new MiniProfilerOptions
  5. {
  6. RouteBasePath = "~/mini-profiler-resources",
  7. PopupRenderPosition = RenderPosition.Right, // defaults to left
  8. PopupMaxTracesToShow = 2, // defaults to 15
  9. ColorScheme = ColorScheme.Auto, // defaults to light
  10. IgnoredPaths = { "/lib/","/css/","images"}
  11. });
  12. }
  13. protected void Application_BeginRequest()
  14. {
  15. MiniProfiler.StartNew();
  16. }
  17. protected void Application_EndRequest()
  18. {
  19. MiniProfiler.Current?.Stop();
  20. }
  1. web.config当中添加如下代码(添加在节点下)
  1. <add name="MiniProfiler" path="mini-profiler-resources/*" verb="*"
  2. type="System.Web.Routing.UrlRoutingModule" resourceType="Unspecified"
  3. preCondition="integratedMode" />
  1. 这时候在swagger当中调用API之后,再访问~/mini-profiler-resources/results路径就会看到如下结果

如何才能使监控结果直接显示在Swagger页面呢?别急,继续如下步骤

  1. 下载默认的index.html页面添加到项目当中,注意:需要将index.html设置为嵌入的资源 官方下载
版权声明:本文为cndota2原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/cndota2/p/13906006.html