練習資料庫紀錄完成
This commit is contained in:
22
README.md
22
README.md
@@ -116,4 +116,24 @@ public static IApplicationBuilder UseCoreProfiler(this IApplicationBuilder app)
|
||||
|
||||
紀錄的詳細如下:
|
||||
|
||||

|
||||

|
||||
|
||||
## CoreProfiler extends DB
|
||||
|
||||
CoreProfiler也可用於紀錄SQL執行,將原本資料庫使用的<code>Connection</code>替換成CoreProfiler實作的<code>Connection</code>就可以紀錄執行的T-SQL指令。
|
||||
|
||||
替換方法如下:
|
||||
|
||||
```C#
|
||||
var connectionString = configuration.GetConnectionString("SQLITE");
|
||||
|
||||
var dbProfiler = ProfilingSession.Current != null
|
||||
? new DbProfiler(ProfilingSession.Current.Profiler)
|
||||
: null;
|
||||
|
||||
return new ProfiledDbConnection(new SqliteConnection(connectionString), dbProfiler);
|
||||
```
|
||||
|
||||
在替換之前,先確認CoreProfiler是否有運行的實體,才替換資料庫連線,執行結果如下:
|
||||
|
||||

|
||||
Reference in New Issue
Block a user