diff --git a/src/Infrastructure/BotSharp.Logger/BotSharp.Logger.csproj b/src/Infrastructure/BotSharp.Logger/BotSharp.Logger.csproj index 324db6cf..a73c11e3 100644 --- a/src/Infrastructure/BotSharp.Logger/BotSharp.Logger.csproj +++ b/src/Infrastructure/BotSharp.Logger/BotSharp.Logger.csproj @@ -1,4 +1,4 @@ - + net6.0 diff --git a/src/Infrastructure/BotSharp.OpenAPI/BotSharpOpenApiExtensions.cs b/src/Infrastructure/BotSharp.OpenAPI/BotSharpOpenApiExtensions.cs index 9fbff43a..fb65580e 100644 --- a/src/Infrastructure/BotSharp.OpenAPI/BotSharpOpenApiExtensions.cs +++ b/src/Infrastructure/BotSharp.OpenAPI/BotSharpOpenApiExtensions.cs @@ -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 }; diff --git a/src/Infrastructure/BotSharp.OpenAPI/Controllers/LoggerController.cs b/src/Infrastructure/BotSharp.OpenAPI/Controllers/LoggerController.cs new file mode 100644 index 00000000..c0e52caa --- /dev/null +++ b/src/Infrastructure/BotSharp.OpenAPI/Controllers/LoggerController.cs @@ -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 GetFullLog() + { + var env = _services.GetRequiredService(); + 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(); + } + } +} diff --git a/src/WebStarter/Program.cs b/src/WebStarter/Program.cs index 419f5b90..9f067666 100644 --- a/src/WebStarter/Program.cs +++ b/src/WebStarter/Program.cs @@ -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();