/// <summary>
        /// 写入操作日志
        /// </summary>
        public async Task InsertAppLogAsync()
        {
            var _QueryString = httpContext.Request.QueryString.ToString();
            var _ApiUrl      = httpContext.Request.Path;
            var _IP          = httpContext.Connection.RemoteIpAddress.ToString();

            //本机不记录
            // if (_IP == "::1") return;

            var body = string.Empty;
            var form = string.Empty;

            //body
            try
            {
                //读取 body 信息
                var reader = new StreamReader(httpContext.Request.Body);
                body = await reader.ReadToEndAsync();

                httpContext.Request.Body.Position = 0;//必须存在

                //Stream stream = httpContext.Request.Body;
                //byte[] buffer = new byte[httpContext.Request.ContentLength.Value];
                //await stream.ReadAsync(buffer, 0, buffer.Length);
                //body = Encoding.UTF8.GetString(buffer);
            }
            catch (Exception)
            {
            }
            //form
            try
            {
                //读取 表单 信息
                var _Form = httpContext.Request.Form;
                if (_Form != null)
                {
                    var _Dictionary = new Dictionary <string, object>();
                    foreach (var key in _Form.Keys)
                    {
                        _Dictionary[key] = _Form[key];
                    }

                    form = JsonConvert.SerializeObject(_Dictionary);
                }
            }
            catch (Exception) { }

            var appLogModel = new Sys_AppLog();

            appLogModel.AppLog_Api         = _ApiUrl;
            appLogModel.AppLog_IP          = _IP;
            appLogModel.AppLog_Form        = form;
            appLogModel.AppLog_QueryString = _QueryString;
            appLogModel.AppLog_FormBody    = body;
            appLogModel.AppLog_UserID      = info?.UserID;

            await dbAppLog.InsertAsync(appLogModel);
        }
Esempio n. 2
0
        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public string Save(Sys_AppLog model)
        {
            db.Commit(() =>
            {
                if (model.AppLog_ID.ToGuid() == Guid.Empty)
                {
                    model.AppLog_ID = db.Insert(model).ToGuid();
                    if (model.AppLog_ID.ToGuid() == Guid.Empty)
                    {
                        throw new MessageBox(this.ErrorMessage);
                    }
                }
                else
                {
                    if (db.UpdateById(model) == 0)
                    {
                        throw new MessageBox(this.ErrorMessage);
                    }
                }
            });

            return(model.AppLog_ID.ToGuidStr());
        }
 public async Task <ApiResult> SaveAsync([FromBody] Sys_AppLog Model)
 => this.ResultOk(await this.service.SaveAsync(Model));
 public async Task <ApiResult> FindListAsync(int Page, int Rows, [FromBody] Sys_AppLog Search)
 => this.ResultOk(await this.service.FindListAsync(Page, Rows, Search));