53 lines
1.5 KiB
C#
53 lines
1.5 KiB
C#
using Microsoft.AspNetCore.Builder;
|
|
using Microsoft.AspNetCore.Diagnostics;
|
|
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
namespace WarhoundConsole
|
|
{
|
|
public class Program
|
|
{
|
|
public static void Main(string[] args)
|
|
{
|
|
try
|
|
{
|
|
MainInternal(args);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Console.WriteLine(e);
|
|
}
|
|
}
|
|
|
|
private static void MainInternal(string[] args)
|
|
{
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
builder.WebHost.UseUrls("http://localhost:80");
|
|
builder.Services.AddControllers();
|
|
builder.Services.AddEndpointsApiExplorer();
|
|
builder.Services.AddSwaggerGen();
|
|
|
|
var app = builder.Build();
|
|
app.UseSwagger();
|
|
app.UseSwaggerUI();
|
|
app.MapControllers();
|
|
app.UseExceptionHandler(ExceptionHandler);
|
|
app.Run();
|
|
}
|
|
|
|
private static void ExceptionHandler(IApplicationBuilder applicationBuilder)
|
|
{
|
|
applicationBuilder.Run(async context =>
|
|
{
|
|
var exceptionHandlerFeature = context.Features.Get<IExceptionHandlerFeature>();
|
|
if (exceptionHandlerFeature != null)
|
|
{
|
|
var exception = exceptionHandlerFeature.Error;
|
|
|
|
// Do something here
|
|
}
|
|
});
|
|
}
|
|
}
|
|
}
|