Entity FrameworkのコアでWEBAPIと分析プロジェクトで使用MiniProfiler

Entity FrameworkのコアでWEBAPIと分析プロジェクトで使用MiniProfiler

取り付け設定MiniProfiler

既存のASP.NET MVCコアWEBAPIプロジェクトで、NugetのインストールによってMiniProfiler

Install-Package MiniProfiler.AspNetCore.Mvc MiniProfiler.EntityFrameworkCore

またによって実装されNuget Package Manager、実装ビジュアライザ

11.png

次のステップは3段階の合計を設定し、MiniProfilerを使用する方法です。

第一歩方法は、追加しますStartup.csConfigureServicesservices.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();
    }

第2のステップは、に来る方法、添加Startup.csConfigureapp.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アドレスに関連する結果を表示する3つの合計です。

1。/profiler/results-index

  • その結果、インデックスページを見てください:

12.png

これは、各レコードにAPI呼び出しの結果を表しています。あなたはこのコールAPI 1578.4ミリ秒単位の合計時間を見ることができます。

2。/profiler/results

  • このページの詳細な結果は結果ページでリンク、上の結果、インデックスページのクリックからのAPI呼び出しを入力します:

13.png

これは、各SQL文の実行時間に固有の各API呼び出しプロセスの分析、コンテンツを表します。

3。/profiler/results-list

  • 結果リストのページを見てください:

14.png

実際には、すべてのコールのセットは、各APIの結果を記録することを言います。

第三に、ケース出典:

MiniProfilerCoreWebApiDemo

おすすめ

転載: www.cnblogs.com/Run2948/p/11247857.html