You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
1.7 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using zzz.Common;
using Microsoft.Extensions.DependencyInjection;
using System;
using StackExchange.Profiling.Storage;
namespace zzz.Extensions
{
/// <summary>
/// MiniProfiler 启动服务
/// </summary>
public static class MiniProfilerSetup
{
public static void AddMiniProfilerSetup(this IServiceCollection services)
{
if (services == null) throw new ArgumentNullException(nameof(services));
if(Appsettings.app(new string[] { "Middleware", "MiniProfiler" }).ObjToBool())
{
services.AddMiniProfiler(options =>
{
options.RouteBasePath = "/profiler";//注意这个路径要和下边 index.html 脚本配置中的一致,
(options.Storage as MemoryCacheStorage).CacheDuration = TimeSpan.FromMinutes(10);
options.PopupRenderPosition = StackExchange.Profiling.RenderPosition.Left;
options.PopupShowTimeWithChildren = true;
});
}
// 3.x使用MiniProfiler必须要注册MemoryCache服务
// services.AddMiniProfiler(options =>
// {
// options.RouteBasePath = "/profiler";
// //(options.Storage as MemoryCacheStorage).CacheDuration = TimeSpan.FromMinutes(10);
// options.PopupRenderPosition = StackExchange.Profiling.RenderPosition.Left;
// options.PopupShowTimeWithChildren = true;
// // 可以增加权限
// //options.ResultsAuthorize = request => request.HttpContext.User.IsInRole("Admin");
// //options.UserIdProvider = request => request.HttpContext.User.Identity.Name;
// }
//);
}
}
}