mirror of
https://github.com/techgarage-ir/MTWireGuard.git
synced 2025-08-17 08:01:00 +02:00
Added Serilog to manage logs
Handle required fields while starting
This commit is contained in:
parent
6fbfaa1007
commit
b128154c60
17 changed files with 749 additions and 154 deletions
120
UI/Program.cs
120
UI/Program.cs
|
@ -3,63 +3,91 @@ using MTWireGuard.Middlewares;
|
|||
using MTWireGuard.Application;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
using MTWireGuard.Application.MinimalAPI;
|
||||
using Serilog;
|
||||
using Serilog.Exceptions.Core;
|
||||
using Serilog.Exceptions;
|
||||
using System.Configuration;
|
||||
using Serilog.Ui.Web;
|
||||
using Serilog.Ui.Web.Authorization;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
builder.Services.AddApplicationServices();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
if (!app.Environment.IsDevelopment())
|
||||
internal class Program
|
||||
{
|
||||
app.UseExceptionHandler("/Error");
|
||||
app.UseHsts();
|
||||
}
|
||||
public static bool isValid { get; private set; }
|
||||
public static string validationMessage { get; private set; }
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
|
||||
var serviceScope = app.Services.CreateScope().ServiceProvider;
|
||||
|
||||
// Validate Prerequisite
|
||||
var validator = new SetupValidator(serviceScope);
|
||||
await validator.Validate();
|
||||
|
||||
if (!app.Environment.IsDevelopment())
|
||||
app.UseStaticFiles();
|
||||
else
|
||||
app.UseStaticFiles(new StaticFileOptions()
|
||||
private static async Task Main(string[] args)
|
||||
{
|
||||
OnPrepareResponse = context =>
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
builder.Services.AddControllersWithViews();
|
||||
builder.Services.AddExceptionHandler<ExceptionHandler>();
|
||||
builder.Services.AddProblemDetails();
|
||||
builder.Services.AddApplicationServices();
|
||||
|
||||
builder.Host.UseSerilog(Helper.LoggerConfiguration());
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
|
||||
var serviceScope = app.Services.CreateScope().ServiceProvider;
|
||||
|
||||
// Validate Prerequisite
|
||||
var validator = new SetupValidator(serviceScope);
|
||||
isValid = await validator.Validate();
|
||||
|
||||
if (!app.Environment.IsDevelopment())
|
||||
{
|
||||
context.Context.Response.Headers.Append("Cache-Control", "no-cache, no-store");
|
||||
context.Context.Response.Headers.Append("Expires", "-1");
|
||||
app.UseStaticFiles();
|
||||
app.UseHsts();
|
||||
}
|
||||
});
|
||||
else
|
||||
app.UseStaticFiles(new StaticFileOptions()
|
||||
{
|
||||
OnPrepareResponse = context =>
|
||||
{
|
||||
context.Context.Response.Headers.Append("Cache-Control", "no-cache, no-store");
|
||||
context.Context.Response.Headers.Append("Expires", "-1");
|
||||
}
|
||||
});
|
||||
|
||||
app.UseDependencyCheck();
|
||||
app.UseClientReporting();
|
||||
app.UseExceptionHandling();
|
||||
//app.UseAntiForgery();
|
||||
app.UseExceptionHandler();
|
||||
app.UseClientReporting();
|
||||
//app.UseAntiForgery();
|
||||
app.UseRouting();
|
||||
|
||||
app.UseRouting();
|
||||
app.UseAuthentication();
|
||||
app.UseAuthorization();
|
||||
|
||||
app.UseAuthentication();
|
||||
app.UseAuthorization();
|
||||
app.UseSession();
|
||||
|
||||
app.UseSession();
|
||||
app.MapRazorPages();
|
||||
|
||||
app.MapRazorPages();
|
||||
app.
|
||||
MapGroup("/api/").
|
||||
MapGeneralApi();
|
||||
|
||||
app.
|
||||
MapGroup("/api/").
|
||||
MapGeneralApi();
|
||||
app.UseCors(options =>
|
||||
{
|
||||
options.AllowAnyHeader();
|
||||
options.AllowAnyMethod();
|
||||
options.AllowAnyOrigin();
|
||||
});
|
||||
|
||||
app.UseCors(options =>
|
||||
{
|
||||
options.AllowAnyHeader();
|
||||
options.AllowAnyMethod();
|
||||
options.AllowAnyOrigin();
|
||||
});
|
||||
app.UseSerilogRequestLogging();
|
||||
|
||||
app.Run();
|
||||
app.UseSerilogUi(options =>
|
||||
{
|
||||
options.RoutePrefix = "Debug";
|
||||
options.InjectStylesheet("/assets/lib/boxicons/css/boxicons.min.css");
|
||||
options.InjectStylesheet("/assets/css/serilogui.css");
|
||||
options.InjectJavascript("/assets/js/serilogui.js");
|
||||
options.Authorization.AuthenticationType = AuthenticationType.Jwt;
|
||||
options.Authorization.Filters =
|
||||
[
|
||||
new SerilogUiAuthorizeFilter()
|
||||
];
|
||||
});
|
||||
|
||||
app.Run();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue