概述

1、存储异常信息
2、存储业务日志调试信息

Startup.cs

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

app.json

    "trackLogDbType": "MySql", //操作日志存储的数据库类别  File MySql Oracle PostgreSql Sqlite Sqlserver

db.provider.Production.json/db.provider.Development.json


  //异常等日志信息
  "ConnTrackLog": {
    "name": "ConnTrackLog",
    "databaseType": "MySql",
    "providerName": "MySql.Data.MySqlClient",
    "remark": "",
    "read": [
    "Data Source=localhost;Initial Catalog={ownerId}_auth_log_track;User Id=root;Password={password};charset=utf8"
    ],
    "write": [
      "Data Source=localhost;Initial Catalog={ownerId}_auth_log_track;User Id=root;Password={password};charset=utf8"
    ]
  },

注入服务 IOperateLogTrack _perateLogTrack

 /// <summary>
        /// 系统配置信息
        /// </summary>
        private readonly IConfiguration _configuration;
        private readonly RequestDelegate _next;
        private readonly IWebHostEnvironment _env;
        private readonly ILogger<GlobalExceptionMiddleware> _logger;


        private readonly IOperateLogTrack _perateLogTrack;

        /// <summary>
        /// 
        /// </summary>
        /// <param name="next"></param>
        /// <param name="env"></param>
        /// <param name="logger"></param>
        /// <param name="configuration"></param>
        public GlobalExceptionMiddleware(IOperateLogTrack perateLogTrack, RequestDelegate next, IWebHostEnvironment env, ILogger<GlobalExceptionMiddleware> logger, IConfiguration configuration)
        {
            _next = next;
            _env = env;
            _logger = logger;
            _configuration = configuration;
            _perateLogTrack = perateLogTrack;
        }

调用

 string body = null;
            //System.Text.Json.JsonSerializer.Serialize(context, new JsonSerializerOptions { PropertyNameCaseInsensitive = true, PropertyNamingPolicy = JsonNamingPolicy.CamelCase })
            _perateLogTrack.Save(context, new PFGlobalParameter { ModuleKey = "gloabal-exception", RequestModuleType = RequestModuleType.Exception }, null, ex, body, null, null, null);
文档更新时间: 2021-08-07 12:09   作者:admin