fix 服务端日志

This commit is contained in:
2024-07-19 20:49:40 +08:00
parent eb186fc81d
commit 97c4384521

View File

@@ -1,10 +1,12 @@
using Dlhis.Canteen.Dishes.Request;
using System.Diagnostics;
using Dlhis.Canteen.Dishes.Request;
using Dlhis.Canteen.Order.Request;
using Dlhis.Canteen.Order.Response;
using Dlhis.Canteen.Order.Services;
using Kurisu.AspNetCore.DataAccess.Dto;
using Kurisu.AspNetCore.DataAccess.SqlSugar.Aop;
using Kurisu.AspNetCore.UnifyResultAndValidation;
using Kurisu.AspNetCore.Utils.Extensions;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
@@ -20,11 +22,13 @@ public class OrdersController : ControllerBase
{
private readonly IOrderService _orderService;
private readonly IBookingOrderService _bookingOrderService;
private readonly ILogger<OrdersController> _logger;
public OrdersController(IOrderService orderService, IBookingOrderService bookingOrderService)
public OrdersController(IOrderService orderService, IBookingOrderService bookingOrderService, ILogger<OrdersController> logger)
{
_orderService = orderService;
_bookingOrderService = bookingOrderService;
_logger = logger;
}
/// <summary>
@@ -37,7 +41,15 @@ public class OrdersController : ControllerBase
[IgnoreTenant]
public async Task<DefaultApiResult<OrderResultResponse>> AddAsync(OrderAddRequest request)
{
return await _orderService.AddAsync(request);
var sw = Stopwatch.StartNew();
try
{
return await _orderService.AddAsync(request);
}
finally
{
_logger.LogInformation("消费请求:{json}. 耗时:{time}", request.ToJson(), sw.ElapsedMilliseconds);
}
}
/// <summary>