修改日志

This commit is contained in:
zpc 2024-09-04 04:50:58 +08:00
parent c3e4130548
commit e295e8d91a
3 changed files with 25 additions and 12 deletions

View File

@ -54,8 +54,16 @@ namespace HuanMeng.MiaoYu.WebPayApi.Controllers
[HttpPost("{tenant?}/{pay?}/{orderId?}/{sign?}")]
public async Task<string> Post(string? tenant, string? pay, string? orderId, string? sign)
{
#region
var context = httpContextAccessor.HttpContext;
context.Request.EnableBuffering(); // Enable buffering to allow the body to be read multiple times
using (var reader = new StreamReader(context.Request.Body, Encoding.UTF8, true, 1024, leaveOpen: true))
{
var bodyContent = await reader.ReadToEndAsync();
logger.LogInformation($"请求支付回调接口,请求路径: {context.Request.Path}, 请求Body: {bodyContent}");
context.Request.Body.Position = 0;
}
#region
var orderInfo = PaymentExtend.ParseCustomString(orderId);
string newSign = $"{tenant}{orderId}{orderInfo.UserId}";
newSign = MD5Encryption.ComputeMD5Hash(newSign);
@ -109,7 +117,7 @@ namespace HuanMeng.MiaoYu.WebPayApi.Controllers
await dao.daoDbMiaoYu.context.SaveChangesAsync();
return $"error;用户不存在";
}
using (IDbContextTransaction transaction = dao.daoDbMiaoYu.context.Database.BeginTransaction(System.Data.IsolationLevel.RepeatableRead))
using (IDbContextTransaction transaction = dao.daoDbMiaoYu.context.Database.BeginTransaction(System.Data.IsolationLevel.ReadUncommitted))
{
try
{
@ -133,13 +141,7 @@ namespace HuanMeng.MiaoYu.WebPayApi.Controllers
}
}
redis.KeyDelete(baseKey);
context.Request.EnableBuffering(); // Enable buffering to allow the body to be read multiple times
using (var reader = new StreamReader(context.Request.Body, Encoding.UTF8, true, 1024, leaveOpen: true))
{
var bodyContent = await reader.ReadToEndAsync();
logger.LogInformation($"请求支付回调接口,请求路径: {context.Request.Path}, 请求Body: {bodyContent}");
context.Request.Body.Position = 0;
}
return $"success";
}

View File

@ -15,6 +15,7 @@
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.20.1" />
<PackageReference Include="Serilog" Version="4.0.0" />
<PackageReference Include="Serilog.AspNetCore" Version="8.0.1" />
<PackageReference Include="Serilog.Expressions" Version="5.0.0" />
<PackageReference Include="Serilog.Extensions.Hosting" Version="8.0.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
<PackageReference Include="Serilog.Sinks.File" Version="6.0.0" />

View File

@ -9,7 +9,7 @@
"Serilog": {
"Using": [ "Serilog.Sinks.Console", "Serilog.Sinks.File" ],
"MinimumLevel": {
"Default": "Information",
"Default": "Debug",
"Override": {
"Microsoft": "Warning",
"System": "Warning"
@ -35,7 +35,12 @@
"restrictedToMinimumLevel": "Error", // // VerboseDebugInformationWarningError Fatal
"shared": true //
// "outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level}] {Message}{NewLine}{Exception}"
}
},
"Filter": [
{
"Expression": "Level == 'Error'"
}
]
},
{
"Name": "File",
@ -45,7 +50,12 @@
"restrictedToMinimumLevel": "Debug", // // VerboseDebugInformationWarningError Fatal
"shared": true //
// "outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level}] {Message}{NewLine}{Exception}"
}
},
"Filter": [
{
"Expression": "Level == 'Debug'"
}
]
}
],
"Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId" ]