|
@@ -1,6 +1,10 @@
|
|
|
using Hotline.Settings;
|
|
|
+using Hotline.Share.Tools;
|
|
|
+using Hotline.Tools;
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
using Microsoft.AspNetCore.Mvc.Filters;
|
|
|
+using Newtonsoft.Json;
|
|
|
+using System.Text;
|
|
|
|
|
|
namespace Hotline.Api.Filter;
|
|
|
|
|
@@ -34,13 +38,32 @@ public class LogFilterAlphaAttribute : ActionFilterAttribute
|
|
|
Name = this.Name,
|
|
|
};
|
|
|
GetMethod(context, systemLog);
|
|
|
- var systemId = await repository.AddAsync(systemLog);
|
|
|
|
|
|
var resultContext = await next();
|
|
|
|
|
|
- var result = context.Result as ObjectResult;
|
|
|
- if (result != null)
|
|
|
- await repository.UpdateResultAsync(systemId, result);
|
|
|
+ if (resultContext.Exception != null)
|
|
|
+ {
|
|
|
+ StringBuilder sbException = new StringBuilder();
|
|
|
+ Exception exception = resultContext.Exception;
|
|
|
+ sbException.AppendLine(exception.Message);
|
|
|
+ if (exception.InnerException != null)
|
|
|
+ sbException.AppendLine(exception.InnerException.Message);
|
|
|
+
|
|
|
+ sbException.AppendLine(LogTool.GetSubString(resultContext.Exception.StackTrace, 4000));
|
|
|
+ systemLog.ExecuteResult = sbException.ToString();
|
|
|
+ systemLog.Status = 0;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ systemLog.Status = 1;
|
|
|
+ ObjectResult result = context.Result as ObjectResult;
|
|
|
+ if (result != null)
|
|
|
+ {
|
|
|
+ systemLog.ExecuteResult = JsonConvert.SerializeObject(result.Value);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ await repository.AddAsyncNoException(systemLog);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -49,16 +72,20 @@ public class LogFilterAlphaAttribute : ActionFilterAttribute
|
|
|
var request = context.HttpContext.Request;
|
|
|
try
|
|
|
{
|
|
|
- systemLog.ExecuteUrl = request.Method.ToUpper() + "|" + request.Path;
|
|
|
- if (request.Method.ToUpper() == "GET")
|
|
|
+ if (request != null)
|
|
|
{
|
|
|
- systemLog.ExecuteParam = request.QueryString.ToString();
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- if (request.ContentType?.IndexOf("multipart/form-data", StringComparison.Ordinal) == -1)
|
|
|
+ systemLog.ExecuteUrl = request.Method.ToUpper() + "|" + request.Path;
|
|
|
+ if (request.Method.ToUpper() == "GET")
|
|
|
+ {
|
|
|
+ systemLog.ExecuteParam = request.QueryString.ToString();
|
|
|
+ }
|
|
|
+ else
|
|
|
{
|
|
|
- systemLog.ExecuteParam = context.ActionArguments.Values.FirstOrDefault();
|
|
|
+ if (request.ContentType?.IndexOf("multipart/form-data", StringComparison.Ordinal) == -1 && context.ActionArguments.Values.FirstOrDefault() != null)
|
|
|
+ {
|
|
|
+ systemLog.ExecuteParam = context.ActionArguments.Values.FirstOrDefault();
|
|
|
+ systemLog.ExecuteParam = systemLog.ExecuteParam.ToJson().FromJson<dynamic>();
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|