Galosys.Foundation.MiniProfiler 26.8.3.1

dotnet add package Galosys.Foundation.MiniProfiler --version 26.8.3.1
                    
NuGet\Install-Package Galosys.Foundation.MiniProfiler -Version 26.8.3.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Galosys.Foundation.MiniProfiler" Version="26.8.3.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Galosys.Foundation.MiniProfiler" Version="26.8.3.1" />
                    
Directory.Packages.props
<PackageReference Include="Galosys.Foundation.MiniProfiler" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Galosys.Foundation.MiniProfiler --version 26.8.3.1
                    
#r "nuget: Galosys.Foundation.MiniProfiler, 26.8.3.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Galosys.Foundation.MiniProfiler@26.8.3.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Galosys.Foundation.MiniProfiler&version=26.8.3.1
                    
Install as a Cake Addin
#tool nuget:?package=Galosys.Foundation.MiniProfiler&version=26.8.3.1
                    
Install as a Cake Tool

Galosys.Foundation.MiniProfiler

成熟度: 🟡 可用 — 功能完整,测试或文档可能不完善

MiniProfiler 集成模块,为 ASP.NET Core 应用提供性能分析、SQL 监控和请求追踪能力。

功能概览

1. 性能分析

  • HTTP 请求性能监控
  • SQL 查询性能追踪
  • MVC 过滤器与视图性能分析
  • 连接打开/关闭追踪

2. 可视化界面

  • 实时性能数据展示
  • SQL 格式化显示
  • 深色主题支持
  • 路由路径可配置

3. Entity Framework Core 集成

  • EF Core 查询性能监控
  • 自动生成 SQL 日志
  • 查询执行时间统计

安装

<PackageReference Include="Galosys.Foundation.MiniProfiler" Version="x.x.x" />

使用

注册服务

// 在 Startup.cs 或 Program.cs 中注册
services.AddMiniProfiler();

配置选项

services.AddMiniProfiler(options =>
{
    // 路由路径配置
    options.RouteBasePath = "/profiler";
    
    // 缓存时间配置
    (options.Storage as MemoryCacheStorage).CacheDuration = TimeSpan.FromMinutes(60);
    
    // SQL 格式化器
    options.SqlFormatter = new StackExchange.Profiling.SqlFormatters.InlineFormatter();
    
    // 连接追踪
    options.TrackConnectionOpenClose = true;
    
    // 主题颜色
    options.ColorScheme = StackExchange.Profiling.ColorScheme.Dark;
    
    // MVC 过滤器性能分析
    options.EnableMvcFilterProfiling = true;
    
    // MVC 视图性能分析
    options.EnableMvcViewProfiling = true;
})
.AddEntityFramework();

使用 MiniProfileService

// 控制器自动注入
[RestController, AllowAnonymous]
public class MiniProfileService
{
    private readonly IHttpContextAccessor _accessor;

    public MiniProfileService(IHttpContextAccessor accessor)
    {
        _accessor = accessor;
    }

    public HtmlString Html()
    {
        return MiniProfiler.Current.RenderIncludes(_accessor.HttpContext);
    }
}

在视图中显示性能数据


@using StackExchange.Profiling
@inject IHttpContextAccessor HttpContextAccessor

@{
    var profiler = MiniProfiler.Current;
    if (profiler != null)
    {
        @profiler.RenderIncludes(HttpContextAccessor.HttpContext)
    }
}

核心类

分类 说明
服务 MiniProfileService 提供性能数据渲染的 REST 控制器
扩展 ServiceCollectionExtensions.AddMiniProfiler 注册 MiniProfiler 服务
配置 MiniProfilerOptions MiniProfiler 配置选项

配置说明

路由配置

  • 默认路径: /profiler
  • 可通过 RouteBasePath 自定义

存储配置

  • 默认: 内存缓存
  • 缓存时间: 60 分钟
  • 支持自定义存储实现

SQL 格式化

  • InlineFormatter: 内联格式化(默认)
  • SqlServerFormatter: SQL Server 格式化
  • 支持自定义格式化器

颜色主题

  • ColorScheme.Light: 浅色主题
  • ColorScheme.Dark: 深色主题(默认)

依赖项

  • miniprofiler.aspnetcore.mvc
  • miniprofiler.entityframeworkcore
  • Galosys.Foundation.AspNetCore.DynamicApi
  • Galosys.Foundation.Core

目录结构

Galosys.Foundation.MiniProfiler/
├── Galosys/Foundation/MiniProfiler/
│   └── MiniProfileService.cs
└── Microsoft/Extensions/DependencyInjection/
    └── ServiceCollectionExtensions.cs

注意事项

  1. 生产环境部署: 建议配置授权规则,限制性能分析数据的访问
  2. 内存占用: 长时间运行的应用建议调整缓存时间
  3. SQL 日志: 大量 SQL 查询可能影响性能,建议仅在开发环境启用详细日志
  4. 跨域支持: 确保 /profiler 路由的跨域配置正确

示例项目

参考 samples/Dev.API 项目中的 MiniProfiler 集成示例。

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
26.8.3.1 19 8/3/2026
26.7.31.1 37 7/31/2026
26.7.30.1 64 7/30/2026
26.7.29.1 73 7/29/2026
26.7.28.1 82 7/28/2026
26.7.26.2 89 7/26/2026
26.7.26.1 81 7/25/2026
26.7.25.1 97 7/25/2026
26.7.24.2 98 7/24/2026
26.7.24.1 87 7/24/2026
26.7.22.1 88 7/23/2026
26.7.21.1 82 7/22/2026
26.7.20.2 82 7/20/2026
26.7.20.1 89 7/20/2026
26.7.19.3 86 7/19/2026
26.7.19.2 89 7/19/2026
26.7.19.1 87 7/19/2026
26.7.18.2 89 7/18/2026
26.7.18.1 91 7/18/2026
26.7.14.1 94 7/14/2026
Loading failed