IRequestLoggingFeature
This commit is contained in:
parent
31655bf890
commit
810aab081f
13
FastGithub.HttpServer/IRequestLoggingFeature.cs
Normal file
13
FastGithub.HttpServer/IRequestLoggingFeature.cs
Normal file
@ -0,0 +1,13 @@
|
||||
namespace FastGithub.HttpServer
|
||||
{
|
||||
/// <summary>
|
||||
/// 请求日志特性
|
||||
/// </summary>
|
||||
public interface IRequestLoggingFeature
|
||||
{
|
||||
/// <summary>
|
||||
/// 是否启用
|
||||
/// </summary>
|
||||
bool Enable { get; set; }
|
||||
}
|
||||
}
|
||||
@ -32,6 +32,8 @@ namespace FastGithub.HttpServer
|
||||
/// <returns></returns>
|
||||
public async Task InvokeAsync(HttpContext context, RequestDelegate next)
|
||||
{
|
||||
var feature = new RequestLoggingFeature();
|
||||
context.Features.Set<IRequestLoggingFeature>(feature);
|
||||
var stopwatch = Stopwatch.StartNew();
|
||||
|
||||
try
|
||||
@ -43,6 +45,11 @@ namespace FastGithub.HttpServer
|
||||
stopwatch.Stop();
|
||||
}
|
||||
|
||||
if (feature.Enable == false)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var request = context.Request;
|
||||
var response = context.Response;
|
||||
var message = $"{request.Method} {request.Scheme}://{request.Host}{request.Path} responded {response.StatusCode} in {stopwatch.Elapsed.TotalMilliseconds} ms";
|
||||
@ -119,5 +126,10 @@ namespace FastGithub.HttpServer
|
||||
}
|
||||
return builder.ToString();
|
||||
}
|
||||
|
||||
private class RequestLoggingFeature : IRequestLoggingFeature
|
||||
{
|
||||
public bool Enable { get; set; } = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -146,7 +146,7 @@
|
||||
<TabControl Style="{StaticResource TabControlWithUnderLineStyle}" Foreground="Black" Background="Transparent" BorderBrush="Transparent" BorderThickness="0">
|
||||
<TabItem Style="{StaticResource TabItemExWithUnderLineStyle}" Cursor="Hand" Header="流量监控" Height="40" Width="100" Margin="5 0" FontSize="18">
|
||||
<Grid Background="#ddd">
|
||||
<WebBrowser Source="http://127.0.0.1/flow.html" />
|
||||
<WebBrowser Source="http://127.0.0.1/flow.html"/>
|
||||
</Grid>
|
||||
</TabItem>
|
||||
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
using FastGithub.Configuration;
|
||||
using FastGithub.FlowAnalyze;
|
||||
using FastGithub.HttpServer;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
@ -70,6 +71,11 @@ namespace FastGithub
|
||||
{
|
||||
endpoint.MapGet("/flowRates", context =>
|
||||
{
|
||||
var feature = context.Features.Get<IRequestLoggingFeature>();
|
||||
if (feature != null)
|
||||
{
|
||||
feature.Enable = false;
|
||||
}
|
||||
var flowRate = context.RequestServices.GetRequiredService<IFlowAnalyzer>().GetFlowRate();
|
||||
return context.Response.WriteAsJsonAsync(flowRate);
|
||||
});
|
||||
|
||||
@ -20,7 +20,7 @@
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<body onContextMenu="return false">
|
||||
<div id="chart"></div>
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
Loading…
Reference in New Issue
Block a user