安装配置MiniProfiler 在现有的ASP.net core mvc webapi 项目里,通过Nuget安装MiniProfiler: Install-Package Min
在现有的ASP.net core mvc webapi 项目里,通过Nuget安装MiniProfiler
:
Install-Package MiniProfiler.Aspnetcore.Mvc MiniProfiler.EntityFrameworkCore
当然也可以通过Nuget Package Manager
可视化工具安装
接下来就是如何配置和使用 MiniProfiler 了,总共分三步:
第一步,来到Startup.cs
的ConfigureServices
方法里,添加services.AddMiniProfiler();
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.ADDDbContext<DataContext>(options => options.UsesqlServer(Configuration.GetConnectionString("DataContext")));
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
// 首先添加一个配置选项,用于访问分析结果:
services.AddMiniProfiler(options =>
{
// 设定弹出窗口的位置是左下角
options.PopupRenderPosition = RenderPosition.BottomLeft;
// 设定在弹出的明细窗口里会显式Time With Children这列
options.PopupShowTimeWithChildren = true;
// 设定访问分析结果URL的路由基地址
options.RouteBasePath = "/profiler";
})
// 然后在之前的配置后边加上AddEntityFramework():
.AddEntityFramework();
}
第二步,来到来到Startup.cs
的Configure
方法里,添加app.UseMiniProfiler();
// This method gets called by the runtime. Use this method to configure the Http request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
...
// 最重要的一点是就是配置中间件在管道中的位置,一定要把它放在UseMvc()方法之前。
app.UseMiniProfiler();
app.UseMvc();
}
第三步、运行程序,一共有3个可查看分析结果相关的URL地址:
它表示每次调用api的记录结果。可以看到本次调用API的总时间为1578.4毫秒。
它表示每次调用API的过程分析结果,具体到每一条SQL语句的内容和执行时间。
它其实就表示每个API的所有调用记录结果的集合。
MiniProfilerCoreWEBApiDemo
到此这篇关于ASP.net core在WebApi项目中使用MiniProfiler分析Entity Framework Core的文章就介绍到这了。希望对大家的学习有所帮助,也希望大家多多支持编程网。
--结束END--
本文标题: ASP.NETCore在WebApi项目中使用MiniProfiler分析EntityFrameworkCore
本文链接: https://www.lsjlt.com/news/139468.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2023-05-21
2023-05-21
2023-05-21
2023-05-21
2023-05-20
2023-05-20
2023-05-20
2023-05-20
2023-05-20
2023-05-20
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0