mirror of
https://github.com/nsnail/NetAdmin.git
synced 2025-12-21 14:05:47 +08:00
wip: 🧠 初步的框架
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
namespace NetAdmin.Infrastructure.Extensions;
|
||||
|
||||
/// <summary>
|
||||
/// HttpRequestMessage 扩展方法
|
||||
/// </summary>
|
||||
public static class HttpRequestMessageExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// 将Http请求的Uri、Header、Body打包成Json字符串
|
||||
/// </summary>
|
||||
public static async Task<string> BuildJsonAsync(this HttpRequestMessage me)
|
||||
{
|
||||
var body = me?.Content == null ? null : await me.Content!.ReadAsStringAsync();
|
||||
return new { Uri = me?.RequestUri, Header = me?.ToString(), Body = body }.ToJson();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 记录日志
|
||||
/// </summary>
|
||||
public static async Task<HttpRequestMessage> LogAsync<T>(this HttpRequestMessage me, ILogger<T> logger)
|
||||
{
|
||||
logger.Info($"{Ln.请求}: {await me.BuildJsonAsync()}");
|
||||
return me;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user