Use MiniProfiler in WebApi and analysis project in Entity Framework Core

Use MiniProfiler in WebApi and analysis project in Entity Framework Core

A mounting configuration MiniProfiler

In the existing ASP.NET Core MVC WebApi project, by Nuget installation MiniProfiler:

Install-Package MiniProfiler.AspNetCore.Mvc MiniProfiler.EntityFrameworkCore

Also be implemented by Nuget Package Managermounting visualizer

11.png

The next step is how to configure and use MiniProfiler a total of three steps:

The first step to Startup.csthe ConfigureServicesmethod, the addedservices.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();
    }

The second step, to come to Startup.csthe Configuremethod, the addedapp.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();
    }

The third step is to run the program, a total of 3 to view the results related to the URL address:

1./profiler/results-index

  • Look at the results-index page:

12.png

It represents each record the results of API calls. You can see the total time for this call API 1578.4 milliseconds.

2./profiler/results

  • The detailed results of this page to enter the API call from the result-index page click on the link, which is the result page:

13.png

It represents each API call process analysis, content specific to each SQL statement and execution time.

3./profiler/results-list

  • Look at the result-list page:

14.png

In fact, it says that the set of all calls record the results of each API.

Third, Case Source:

MiniProfilerCoreWebApiDemo

Guess you like

Origin www.cnblogs.com/Run2948/p/11247857.html