//注入基础服务 便于全局控制

services.AddPFOP();


"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
    "systemLog": true,
    "browerMinute": 2,
    "authExpires": 300, // 60,
    "password": "abcd!ABCD!12", //默认密码,
    "sqlDebug": false, //数据库sql调试, operation
    "analysisDebug": false //性能调试
  },

using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.FileProviders;
using RG3.PF.Abstractions.Interfaces;
using System.IO;
using RG3.PF.Abstractions.Extensions;
using Microsoft.AspNetCore.StaticFiles;
using System.Collections.Generic;
using System.Globalization;
using Microsoft.AspNetCore.Localization;
using System;
using Microsoft.Extensions.DependencyInjection;

namespace RG3.PF.Utilities.Extensions
{
    /// <summary>
    /// 平台基础的操作日志
    /// </summary>
    public static class PFOpAppExtensions
    {
        /// <summary>
        /// 平台基础的操作日志
        /// </summary>
        /// <param name="services"></param>
        /// <param name="operateLog">操作日志</param>
        /// <param name="logTrack">异常和业务日志</param>
        /// <param name="userBehaviorProvider">用户行为</param>
        public static void AddPFOP(this IServiceCollection services, bool operateLog = true, bool logTrack = true,bool userBehaviorProvider=true)
        {
            //添加参数
            services.AddSingleton<IParamProvider, BO.DB.Providers.ParamProvider>();

            if (operateLog)
            {
                //注入操作日志记录
                services.AddSingleton<IOperateLog, BO.DB.Providers.OperateLogProvider>();
            }

            if (logTrack)
            {
                //异常等业务日志信息
                services.AddSingleton<IOperateLogTrack, BO.DB.Providers.OperateLogTrackProvider>();
            }


            if (userBehaviorProvider)
            {
                //异常等业务日志信息
                services.AddSingleton<IUserBehaviorProvider, BO.DB.Providers.UserBehaviorProvider>();
            }
        }
    }
}

服务注入(常用注入代码)


  private readonly IDbContext _db;


        private readonly IMapperProvider _mapper;

        private readonly IAuthProvider _auth;

        ///// <summary>
        ///// 配置
        ///// </summary>
        //private IConfiguration _configDev;



        private readonly IConfigurationBuilderProvider _configurationBuilderService;

        /// <summary>
        /// 日志
        /// </summary>
        private readonly ILogger<OperateLogProvider> _logger;
        private readonly ISubscribePublish _subscribePublishRedis;

        private readonly IParamProvider _param;

        /// <summary>
        /// 注入服务
        /// </summary>
        /// <param name="param"></param>
        /// <param name="configurationBuilderService"></param>
        /// <param name="subscribePublishRedis"></param>
        /// <param name="logger"></param>
        /// <param name="db"></param>
        /// <param name="mapper"></param>
        /// <param name="auth"></param>
        public OperateLogTrackProvider(IParamProvider param,IConfigurationBuilderProvider configurationBuilderService, ISubscribePublishRedis subscribePublishRedis, ILogger<OperateLogProvider> logger, IDbContext db, IMapperProvider mapper, IAuthProvider auth)
        {
            _mapper = mapper;
            _db = db;
            _auth = auth;
            _logger = logger;
            _subscribePublishRedis = subscribePublishRedis;
            _configurationBuilderService = configurationBuilderService;
            _param = param;
            //IConfiguration configDev,
            //_configDev = configDev;
            //_configDev

            //IConfiguration _configDev = _configurationBuilderService.GetConfigurationApp(pf.OwnerId, pf.SysId);
            //////操作日志存储的数据库类别  mysql sqlserver oracle sqlite
            //string dataBaseType = _configDev.GetValue<string>("operation:trackLogDbType");
        }
文档更新时间: 2021-08-25 08:00   作者:admin