"operation": {
    "dimension": {
      //维数据以 value name格式输出
      "kv": true
    },
    "verifyApi": false, //接口合法性验证, 格式如  36位guid|有效时间戳
    "defaultApp": "basis",
    "userBehavior": true,
    "userBehaviorDbType": "MySql",
    "userFilter": true, //用户认证,特定用户访问特定接口
    "userLog": true, //用户操作日志,
    "opLogDbType": "MySql", //操作日志存储的数据库类别  MySql Oracle PostgreSql Sqlite Sqlserver
    "trackLogDbType": "MySql", //业务和异常日志  File MySql Oracle PostgreSql Sqlite Sqlserver
    "systemLogDbType": "MySql", //业务和异常日志  File MySql Oracle PostgreSql Sqlite Sqlserver
    "systemLog": true,
    "browerMinute": 2,
    "authExpires": 300, // 60,
    "password": "abcd!ABCD!12", //默认密码,
    "sqlDebug": false, //数据库sql调试, operation
    "analysisDebug": false, //性能调试
    "devReloadOnChange": false,
    "disabledReloadOnChange": true, // 禁用配置文件变更通知
    "disabledReloadOnChangePro": true
  },
/// <summary>
    /// 调试使用
    /// </summary>
    public class DebugProvider : IDebugProvider
    {


        private readonly IConfiguration _configuration;
        /// <summary>
        /// 
        /// </summary>
        /// <param name="configuration"></param>
        public DebugProvider(IConfiguration configuration)
        {
            _configuration = configuration;
        }

        /// <summary>
        /// 性能分析
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="pfParams"></param>
        /// <param name="content"></param>
        /// <param name="className"></param>
        /// <param name="funName"></param>
        /// <param name="dateStartNow"></param>
        /// <returns></returns>
        public async Task DoAnalysis<T>(PFGlobalParameter pfParams, T content, string className, string funName, DateTime dateStartNow)
        {
            await Task.Run(() =>
             {
                 if (_configuration.GetValue<bool>("operation:analysisDebug"))
                 {
                     FileUtil.LoadAnalysis(className, funName, $"ownerId:{pfParams.OwnerId}--ModuleKey:{pfParams.ModuleKey}--resField:{pfParams.ReponseField}", (DateTime.Now - dateStartNow).TotalMilliseconds);
                 }
             });
        }


        /// <summary>
        /// 执行的sql语句,便于分析
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="pf"></param>
        /// <param name="content"></param>
        /// <returns></returns>
        public async Task DoSql<T>(PFGlobalParameter pf, T content)
        {
            await Task.Run(() =>
            {
                if (_configuration.GetValue<bool>("operation:sqlDebug"))
                {
                    FileUtil.CreateFileAndContent($"~/App_Caches/SqlDebug/{pf.OwnerId}/{pf.ModuleKey}/{DateTime.Now.ToString("yyyyMMdd")}/debug-{Guid.NewGuid()}.json", JsonUtil.Serialize(content ?? default, false, false, false), "UTF8");
                }
            });
        }

        /// <summary>
        /// 错误信息,便于开发源码外调试
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="pf"></param>
        /// <param name="content"></param>
        /// <returns></returns>
        public async Task DoError<T>(PFGlobalParameter pf, T content)
        {
            await Task.Run(() =>
            {
                if (_configuration.GetValue<bool>("operation:sqlDebug"))
                {
                    string funName = "error-funs";
                    FileUtil.CreateFileAndContent($"~/App_Caches/SqlDebug/{pf.OwnerId}/{pf.FunName ?? funName}/{pf.ModuleKey}/{DateTime.Now.ToString("yyyyMMdd")}/error-{Guid.NewGuid()}.json", JsonUtil.Serialize(content ?? default, false, false, false), "UTF8");
                }
            });
        }


文档更新时间: 2022-10-24 13:49   作者:admin