Support download full log.
This commit is contained in:
parent
eaf112fc26
commit
66d45acfc3
|
|
@ -1,4 +1,4 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ public static class BotSharpOpenApiExtensions
|
|||
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(config["Jwt:Key"])),
|
||||
ValidateIssuer = enableValidation,
|
||||
ValidateAudience = enableValidation,
|
||||
ValidateLifetime = enableValidation,
|
||||
ValidateLifetime = enableValidation && !env.IsDevelopment(),
|
||||
ValidateIssuerSigningKey = enableValidation
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,37 @@
|
|||
using Microsoft.AspNetCore.Hosting;
|
||||
using SharpCompress.Compressors.Xz;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Net.Mime;
|
||||
|
||||
namespace BotSharp.OpenAPI.Controllers;
|
||||
|
||||
[Authorize]
|
||||
[ApiController]
|
||||
public class LoggerController : ControllerBase
|
||||
{
|
||||
private readonly IServiceProvider _services;
|
||||
|
||||
public LoggerController(IServiceProvider services)
|
||||
{
|
||||
_services = services;
|
||||
}
|
||||
|
||||
[HttpGet("/logger/full-log")]
|
||||
public async Task<IActionResult> GetFullLog()
|
||||
{
|
||||
var env = _services.GetRequiredService<IWebHostEnvironment>();
|
||||
var logFile = Path.Combine(env.ContentRootPath, "logs", $"log-{DateTime.Now:yyyyMMdd}.txt");
|
||||
if (System.IO.File.Exists(logFile))
|
||||
{
|
||||
using Stream stream = System.IO.File.Open(logFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
|
||||
var bytes = new byte[stream.Length];
|
||||
stream.Read(bytes, 0, (int)stream.Length);
|
||||
return File(bytes, "application/octet-stream", Path.GetFileName(logFile));
|
||||
}
|
||||
else
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -14,7 +14,9 @@ Log.Logger = new LoggerConfiguration()
|
|||
.MinimumLevel.Warning()
|
||||
#endif
|
||||
.WriteTo.Console()
|
||||
.WriteTo.File("logs/log-.txt", rollingInterval: RollingInterval.Day)
|
||||
.WriteTo.File("logs/log-.txt",
|
||||
shared: true,
|
||||
rollingInterval: RollingInterval.Day)
|
||||
.CreateLogger();
|
||||
builder.Host.UseSerilog();
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue