如何使用控制台应用程序来存储数据MIniProfiler [英] How to store MIniProfiler data using Console application
问题描述
我实现一个控制台应用程序,并添加Miniprofiler到这个应用程序。
现在我想Miniprofiler数据存储到数据库中。我有执行该脚本来创建表的数据库。你可以找到脚本这里 <!在 我已审查的答案href=\"https://stackoverflow.com/questions/14695460/how-to-store-mvc-miniprofiler-results\">这
但我怎么能探查值存储到相关的表?
在下面一行MVC是用来存储值:
MiniProfiler.Settings.Storage =新SqlServerStorage(<您的连接字符串>);
我怎么能存储从控制台应用程序,这些价值观?
以上作品充分,并记录预期的数据给 MiniProfilers
和 MiniProfilerTimings
表。设置代码中的关键位是:
- 指定一个存储供应商(你已经有这个)
- 指定探查提供商(单在我的情况)
- 启动/停止探查周围的工作
- 保存探查工作后LI>
代码:
使用StackExchange。剖析;
使用StackExchange.Profiling.Storage;
使用系统;
使用的System.Threading;
//使用StackExchange.Profiling.Helpers.Dapper; //只为表创建
//使用System.Data.SqlClient的; //只为表创建
静态类节目
{
静态无效的主要()
{
常量字符串的ConnectionString =初始目录= MiniProf;数据源=;集成安全=真;;
//使用(VAR康恩=新的SqlConnection(的ConnectionString))
// {
// conn.Open();
// conn.Execute(SqlServerStorage.TableCreationScript);
//}
MiniProfiler.Settings.Storage =新SqlServerStorage(的ConnectionString);
MiniProfiler.Settings.ProfilerProvider =新SingletonProfilerProvider();
MiniProfiler.Settings.ProfilerProvider.Start(ProfileLevel.Info);
DoStuff();
MiniProfiler.Settings.ProfilerProvider.Stop(假);
MiniProfiler.Settings.Storage.Save(MiniProfiler.Current);
}
静态无效DoStuff()
{$ B $使用(MiniProfiler.Current.Step(DoStuff))
{
为B(INT I = 0;我小于5;我++)
{使用(MiniProfiler.Current.Step(循环迭代))
{
的Thread.Sleep(200);
Console.Write(。);
}
}
}
Console.WriteLine();
}
}
I have implement one console application and added Miniprofiler to this application.
Now I want to store Miniprofiler data to database. I have execute the script to create tables to database. You can find script here!
I have reviewed answer on this
But How can I store the profiler values to related tables?
In MVC below line is used to store values:
MiniProfiler.Settings.Storage = new SqlServerStorage("<your connection string>");
How can I store these values from the Console application?
The above works fully, and records the expected data to the MiniProfilers
and MiniProfilerTimings
tables. The key bits in the setup code are:
- specifying a storage provider (you already had this)
- specifying a profiler provider (singleton in my case)
- start/stop the profiler around the work
- save the profiler after the work
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();
}
}
这篇关于如何使用控制台应用程序来存储数据MIniProfiler的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!