5.2 SQL追踪-FreeSql
...小于 1 分钟
简介
支持对ORM框架FreeSql
生成并执行的SQL语句进行跟踪与分析,以方便开发人员优化程序性能。
安装依赖包
示例5.2
(点击查看完整示例代码)
dotnet add package Wing.Consul
dotnet add package Wing.APM.FreeSql
dotnet add package Wing.Persistence
dotnet add package FreeSql.Provider.SqlServer
Install-Package Wing.Consul
Install-Package Wing.APM.FreeSql
Install-Package Wing.Persistence
Install-Package FreeSql.Provider.SqlServer
Program代码
多个freeSql示例可以连续Build,例如:x.AddFreeSql().Build(fsql).Build(fsql2)
using Wing;
var builder = WebApplication.CreateBuilder(args);
builder.Host.AddWing(builder => builder.AddConsul());
// Add services to the container.
builder.Services.AddControllers();
var fsql = new FreeSqlBuilder()
.UseConnectionString(DataType.SqlServer, builder.Configuration["ConnectionStrings:Wing.Demo"])
.UseAutoSyncStructure(true)
.Build();
builder.Services.AddSingleton(typeof(IFreeSql), serviceProvider => fsql);
builder.Services.AddWing()
.AddPersistence(FreeSql.DataType.SqlServer)
.AddAPM(x => x.AddFreeSql().Build(fsql));// 多个freeSql示例可以连续Build,例如x.AddFreeSql().Build(fsql).Build(fsql2)
var app = builder.Build();
// Configure the HTTP request pipeline.
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Run();
查看运行结果
- 运行示例
5.2
,浏览器访问 http://localhost:5210/weatherforecast ,可以看到该http请求追踪信息和SQL的相关信息,如下图: