using System.Text; using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.Extensions.Hosting; using ShellyExporter; using System.Xml.Linq; using NLog.Web; var builder = WebApplication.CreateBuilder(args); // Add services to the container. builder.Services.AddControllers(); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(); if (!builder.Environment.IsDevelopment()) { builder.WebHost.UseKestrel(); builder.WebHost.UseUrls(builder.Configuration["Kst:Url"]); } //Nlog builder.Logging.ClearProviders(); builder.Logging.SetMinimumLevel(LogLevel.Trace); builder.Host.UseNLog(); var app = builder.Build(); // Configure the HTTP request pipeline. if (app.Environment.IsDevelopment()) { app.UseSwagger(); app.UseSwaggerUI(); } app.UseHttpsRedirection(); app.UseAuthorization(); app.MapControllers(); app.Map("/metrics", () => { var sb = new StringBuilder(); foreach (var host in builder.Configuration.GetSection("Hosts").GetChildren()) { var id = "0"; if (host["id"] != "") id = host["id"]; sb.Append(Metrics.Get(host["ip"], host.Path.Replace("Hosts:", ""), (Metrics.Version)Convert.ToInt16(host["version"]), (Metrics.Type)Convert.ToInt16(host["type"]), id).Result); } return sb.ToString(); }); app.Run();