How to store MIniProfiler data using the console application

I have one console application and Miniprofiler has been added to this application.

Now I want to store Miniprofiler data in a database. I created a script to create tables in a database. You can find the script here !

I reviewed the answer on this

But how to save profiler values ​​in related tables?

In MVC below, the line is used to store values:

MiniProfiler.Settings.Storage = new SqlServerStorage("<your connection string>"); 

How to save these values ​​from the console application?

+5
source share
1 answer

The above fully works and writes the expected data to the MiniProfilers and MiniProfilerTimings . The key bits in the installation code are:

  • specifying the storage provider (you already had this)
  • specifying the profiler provider (singleton in my case)
  • start / stop profiler around work.
  • save profiler after work.

the code:

 using StackExchange.Profiling; using StackExchange.Profiling.Storage; using System; using System.Threading; //using StackExchange.Profiling.Helpers.Dapper; // only for table creation //using System.Data.SqlClient; // only for table creation static class Program { static void Main() { const string ConnectionString = "Initial Catalog=MiniProf;Data Source=.;Integrated Security=true;"; //using(var conn = new SqlConnection(ConnectionString)) //{ // conn.Open(); // conn.Execute(SqlServerStorage.TableCreationScript); //} MiniProfiler.Settings.Storage = new SqlServerStorage(ConnectionString); MiniProfiler.Settings.ProfilerProvider = new SingletonProfilerProvider(); MiniProfiler.Settings.ProfilerProvider.Start(ProfileLevel.Info); DoStuff(); MiniProfiler.Settings.ProfilerProvider.Stop(false); MiniProfiler.Settings.Storage.Save(MiniProfiler.Current); } static void DoStuff() { using (MiniProfiler.Current.Step("DoStuff")) { for (int i = 0; i < 5; i++) { using (MiniProfiler.Current.Step("Loop iteration")) { Thread.Sleep(200); Console.Write("."); } } } Console.WriteLine(); } } 
+4
source

Source: https://habr.com/ru/post/1201701/


All Articles