init
This commit is contained in:
85
watcher-monitoring/Program.cs
Normal file
85
watcher-monitoring/Program.cs
Normal file
@@ -0,0 +1,85 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.OpenApi.Models;
|
||||
|
||||
using Serilog;
|
||||
|
||||
using watcher_monitoring.Data;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Serilog konfigurieren – nur Logs, die nicht von Microsoft stammen
|
||||
Log.Logger = new LoggerConfiguration()
|
||||
.MinimumLevel.Information()
|
||||
.MinimumLevel.Override("Microsoft", Serilog.Events.LogEventLevel.Warning)
|
||||
.Enrich.FromLogContext()
|
||||
.WriteTo.File(
|
||||
"logs/watcher-.log",
|
||||
outputTemplate: "[{Timestamp:yyyy-MM-dd HH:mm:ss}] [{Level:u3}] {Message:lj}{NewLine}{Exception}",
|
||||
rollingInterval: RollingInterval.Day
|
||||
)
|
||||
.CreateLogger();
|
||||
|
||||
builder.Host.UseSerilog();
|
||||
|
||||
// ---------- Konfiguration ----------
|
||||
DotNetEnv.Env.Load();
|
||||
builder.Configuration.AddEnvironmentVariables();
|
||||
|
||||
// Konfiguration laden
|
||||
var configuration = builder.Configuration;
|
||||
|
||||
// DbContext - Nur SQLite wird unterstützt
|
||||
var sqliteConnectionString = configuration.GetConnectionString("Sqlite")
|
||||
?? configuration["Database:ConnectionStrings:Sqlite"]
|
||||
?? "Data Source=./persistence/watcher.db";
|
||||
|
||||
builder.Services.AddDbContext<WatcherDbContext>((serviceProvider, options) =>
|
||||
{
|
||||
options.UseSqlite(sqliteConnectionString);
|
||||
});
|
||||
|
||||
// Add services to the container.
|
||||
builder.Services.AddControllersWithViews();
|
||||
|
||||
// Health Checks
|
||||
builder.Services.AddHealthChecks();
|
||||
|
||||
// Swagger API-Dokumentation
|
||||
builder.Services.AddSwaggerGen(options =>
|
||||
{
|
||||
options.SwaggerDoc("v1", new OpenApiInfo { Title = "Watcher-Server API", Version = "v1" });
|
||||
});
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
if (!app.Environment.IsDevelopment())
|
||||
{
|
||||
app.UseExceptionHandler("/Home/Error");
|
||||
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
|
||||
app.UseHsts();
|
||||
}
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
app.UseStaticFiles();
|
||||
|
||||
app.UseRouting();
|
||||
|
||||
// 🔹 Swagger aktivieren
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI(options =>
|
||||
{
|
||||
options.SwaggerEndpoint("/swagger/v1/swagger.json", "Watcher-Server API v1");
|
||||
options.RoutePrefix = "api/v1/swagger";
|
||||
});
|
||||
|
||||
app.UseAuthorization();
|
||||
|
||||
// Health Check Endpoint
|
||||
app.MapHealthChecks("/health");
|
||||
|
||||
app.MapControllerRoute(
|
||||
name: "default",
|
||||
pattern: "{controller=Home}/{action=Index}/{id?}");
|
||||
|
||||
app.Run();
|
||||
Reference in New Issue
Block a user