Merge branch 'release/Telemetry_05'
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<Version>1.0.2603.0407</Version>
|
||||
<Version>1.1.2603.0407</Version>
|
||||
<UserSecretsId>95c9f021-52d1-4390-a670-5810b7b777b0</UserSecretsId>
|
||||
<EnableNETAnalyzers>true</EnableNETAnalyzers>
|
||||
<RunAnalyzersDuringBuild>true</RunAnalyzersDuringBuild>
|
||||
@@ -68,8 +68,9 @@
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="6.0.2" ExcludeAssets="All" />
|
||||
<PackageReference Include="NLog" Version="6.1.0" />
|
||||
<PackageReference Include="NLog" Version="6.1.1" />
|
||||
<PackageReference Include="NLog.Targets.OpenTelemetryProtocol" Version="1.2.6" />
|
||||
<PackageReference Include="NLog.Web.AspNetCore" Version="6.1.2" />
|
||||
<PackageReference Include="OpenTelemetry.Exporter.Console" Version="1.15.0" />
|
||||
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.15.0" />
|
||||
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.15.0" />
|
||||
|
||||
+228
-41
@@ -1,57 +1,244 @@
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using GWMS.Data;
|
||||
using GWMS.UI.Areas.Identity;
|
||||
using GWMS.UI.Data;
|
||||
using HealthChecks.UI.Client;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Components.Authorization;
|
||||
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
|
||||
using Microsoft.AspNetCore.HttpOverrides;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Identity.UI.Services;
|
||||
using Microsoft.AspNetCore.Localization;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Diagnostics.HealthChecks;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using NLog;
|
||||
using NLog.Targets;
|
||||
using NLog.Web;
|
||||
using OpenTelemetry.Resources;
|
||||
using OpenTelemetry.Trace;
|
||||
using StackExchange.Redis;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Globalization;
|
||||
|
||||
namespace GWMS.UI
|
||||
// ====================================================================
|
||||
// 1. IL "FIX" CRITICO PER HTTP/2 (OTLP GRPC)
|
||||
// Deve essere la prima riga eseguita.
|
||||
// ====================================================================
|
||||
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);
|
||||
|
||||
var logger = LogManager.Setup().LoadConfigurationFromAppSettings().GetCurrentClassLogger();
|
||||
logger.Info("GMWS.UI Application Starting Up");
|
||||
|
||||
try
|
||||
{
|
||||
public class Program
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Setup NLog come provider di logging
|
||||
builder.Logging.ClearProviders();
|
||||
builder.Host.UseNLog();
|
||||
|
||||
// ====================================================================
|
||||
// 2. CONFIGURAZIONE SERVIZI (ex ConfigureServices)
|
||||
// ====================================================================
|
||||
var Configuration = builder.Configuration;
|
||||
|
||||
// REDIS setup
|
||||
string connStringRedis = Configuration.GetConnectionString("Redis");
|
||||
string redisSrvAddr = connStringRedis.Contains(":")
|
||||
? connStringRedis.Substring(0, connStringRedis.IndexOf(":"))
|
||||
: "127.0.0.1";
|
||||
|
||||
var redisMultiplexer = ConnectionMultiplexer.Connect(connStringRedis);
|
||||
builder.Services.AddSingleton<IConnectionMultiplexer>(redisMultiplexer);
|
||||
|
||||
// --- SETUP OPENTELEMETRY ---
|
||||
var otelEnabled = Configuration.GetValue<bool>("Otel:EnableTracing", false);
|
||||
var otelEndpoint = Configuration["Otel:Endpoint"];
|
||||
var otelDsn = Configuration["Otel:Dsn"];
|
||||
|
||||
if (otelEnabled)
|
||||
{
|
||||
#region Public Methods
|
||||
var appVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version?.ToString() ?? "1.0.0";
|
||||
|
||||
public static IHostBuilder CreateHostBuilder(string[] args) =>
|
||||
Host.CreateDefaultBuilder(args)
|
||||
.ConfigureWebHostDefaults(webBuilder =>
|
||||
builder.Services.AddOpenTelemetry()
|
||||
.WithTracing(tracerProviderBuilder =>
|
||||
{
|
||||
tracerProviderBuilder
|
||||
.SetResourceBuilder(ResourceBuilder.CreateDefault()
|
||||
.AddService(serviceName: "GWMS", serviceVersion: appVersion))
|
||||
.AddSource("GWMS.Data")
|
||||
.AddSource("GWMS.UI")
|
||||
.AddAspNetCoreInstrumentation(options => {
|
||||
options.Filter = ctx => !ctx.Request.Path.StartsWithSegments("/health");
|
||||
})
|
||||
.AddHttpClientInstrumentation()
|
||||
.AddEntityFrameworkCoreInstrumentation()
|
||||
.AddRedisInstrumentation(redisMultiplexer);
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(otelEndpoint))
|
||||
{
|
||||
webBuilder.UseStartup<Startup>();
|
||||
})
|
||||
.ConfigureLogging(logging =>
|
||||
{
|
||||
logging.ClearProviders();
|
||||
#if DEBUG
|
||||
logging.SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Debug);
|
||||
//logging.SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Information);
|
||||
#else
|
||||
tracerProviderBuilder.AddOtlpExporter(options =>
|
||||
{
|
||||
options.Endpoint = new Uri(otelEndpoint);
|
||||
// Se vai verso otel-collector locale, l'header DSN solitamente non serve qui (lo mette il collector)
|
||||
if (!string.IsNullOrWhiteSpace(otelDsn))
|
||||
{
|
||||
options.Headers = $"uptrace-dsn={otelDsn}";
|
||||
}
|
||||
options.Protocol = OpenTelemetry.Exporter.OtlpExportProtocol.Grpc;
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
logging.SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Information);
|
||||
//logging.SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Warning);
|
||||
#endif
|
||||
});
|
||||
|
||||
public static void Main(string[] args)
|
||||
// Configurazione NLog OTLP Target
|
||||
if (!string.IsNullOrWhiteSpace(otelEndpoint))
|
||||
{
|
||||
var Log = LogManager.GetCurrentClassLogger();
|
||||
try
|
||||
var otlpTarget = new OtlpTarget
|
||||
{
|
||||
Log.Info("GMWS.UI Application Starting Up");
|
||||
CreateHostBuilder(args).Build().Run();
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Log.Error(exception, "Stopped GMWS.UI program because of exception");
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
LogManager.Shutdown();
|
||||
}
|
||||
}
|
||||
Name = "UptraceRealtime",
|
||||
Endpoint = otelEndpoint,
|
||||
ServiceName = "GWMS.Data"
|
||||
};
|
||||
if (!string.IsNullOrWhiteSpace(otelDsn)) { otlpTarget.Headers = $"uptrace-dsn={otelDsn}"; }
|
||||
|
||||
#endregion Public Methods
|
||||
var nlogConfig = LogManager.Configuration ?? new NLog.Config.LoggingConfiguration();
|
||||
nlogConfig.AddTarget(otlpTarget);
|
||||
nlogConfig.AddRule(NLog.LogLevel.Info, NLog.LogLevel.Fatal, otlpTarget);
|
||||
LogManager.Configuration = nlogConfig;
|
||||
LogManager.ReconfigExistingLoggers();
|
||||
}
|
||||
}
|
||||
|
||||
// Init DB Logic
|
||||
string dbServerAddr = Configuration["DbConfig:Server"];
|
||||
string nKey = Configuration["DbConfig:nKey"];
|
||||
string sKey = Configuration["DbConfig:sKey"];
|
||||
DbConfig.InitDb(dbServerAddr, nKey, sKey);
|
||||
DbConfig.CheckUser(nKey, sKey);
|
||||
DbConfig.ExecMigrationMain();
|
||||
|
||||
string connStringDB = DbConfig.CONNECTION_STRING;
|
||||
|
||||
// HealthChecks
|
||||
builder.Services.AddHealthChecks()
|
||||
.AddMySql(connStringDB, "MySql instance")
|
||||
.AddAsyncCheck($"DB PING ({dbServerAddr})", () => GWMS.UI.Health.Checks.PingCheck(dbServerAddr))
|
||||
.AddAsyncCheck($"Redis PING ({redisSrvAddr})", () => GWMS.UI.Health.Checks.PingCheck(redisSrvAddr))
|
||||
.AddProcessAllocatedMemoryHealthCheck(512, "Max Process memory (<512MB)", failureStatus: HealthStatus.Degraded)
|
||||
.AddRedis(connStringRedis, "Redis", failureStatus: HealthStatus.Degraded)
|
||||
.AddAsyncCheck("MySql Root User", () => GWMS.UI.Health.Checks.DbUserRoot("MySql"))
|
||||
.AddAsyncCheck("MySql Identity", () => GWMS.UI.Health.Checks.DbIdentity(DbConfig.DATABASE_NAME))
|
||||
.AddAsyncCheck("MySql PlantLog", () => GWMS.UI.Health.Checks.DbPlantTable(DbConfig.DATABASE_NAME));
|
||||
|
||||
builder.Services.AddHealthChecksUI(s =>
|
||||
{
|
||||
s.AddHealthCheckEndpoint("GWMS_Services", "health");
|
||||
s.SetEvaluationTimeInSeconds(60);
|
||||
s.SetHeaderText("GWMS Health Check Status");
|
||||
}).AddInMemoryStorage();
|
||||
|
||||
// Identity & DB
|
||||
var serverVersion = DbConfig.MysqlServerVersion(connStringDB);
|
||||
builder.Services.AddDbContext<UserIdentityDbContext>(options =>
|
||||
options.UseMySql(connStringDB, serverVersion));
|
||||
|
||||
builder.Services.AddDefaultIdentity<IdentityUser>(options => options.SignIn.RequireConfirmedAccount = true)
|
||||
.AddRoles<IdentityRole>()
|
||||
.AddEntityFrameworkStores<UserIdentityDbContext>();
|
||||
|
||||
// Auth & Cookies
|
||||
builder.Services.ConfigureApplicationCookie(o =>
|
||||
{
|
||||
o.ExpireTimeSpan = TimeSpan.FromDays(30);
|
||||
o.SlidingExpiration = true;
|
||||
});
|
||||
builder.Services.Configure<DataProtectionTokenProviderOptions>(o => o.TokenLifespan = TimeSpan.FromHours(3));
|
||||
|
||||
// Email
|
||||
builder.Services.AddTransient<IEmailSender, MailKitEmailSender>();
|
||||
builder.Services.Configure<MailKitEmailSenderOptions>(options =>
|
||||
{
|
||||
options.Host_Address = Configuration["ExternalProviders:MailKit:SMTP:Address"];
|
||||
options.Host_Port = Convert.ToInt32(Configuration["ExternalProviders:MailKit:SMTP:Port"]);
|
||||
options.Host_Username = Configuration["ExternalProviders:MailKit:SMTP:Account"];
|
||||
options.Host_Password = Configuration["ExternalProviders:MailKit:SMTP:Password"];
|
||||
options.Sender_EMail = Configuration["ExternalProviders:MailKit:SMTP:SenderEmail"];
|
||||
options.Sender_Name = Configuration["ExternalProviders:MailKit:SMTP:SenderName"];
|
||||
});
|
||||
|
||||
builder.Services.AddLocalization();
|
||||
builder.Services.AddRazorPages();
|
||||
builder.Services.AddServerSideBlazor();
|
||||
builder.Services.AddDatabaseDeveloperPageExceptionFilter();
|
||||
|
||||
// Services
|
||||
builder.Services.AddScoped<AuthenticationStateProvider, RevalidatingIdentityAuthenticationStateProvider<IdentityUser>>();
|
||||
builder.Services.AddScoped<GWMSDataService>();
|
||||
builder.Services.AddScoped<MessageService>();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// ====================================================================
|
||||
// 3. CONFIGURAZIONE PIPELINE (ex Configure)
|
||||
// ====================================================================
|
||||
|
||||
app.UsePathBase(Configuration["RuntimeOpt:BaseAppPath"]);
|
||||
|
||||
if (app.Environment.IsDevelopment())
|
||||
{
|
||||
app.UseDeveloperExceptionPage();
|
||||
app.UseMigrationsEndPoint();
|
||||
}
|
||||
else
|
||||
{
|
||||
app.UseExceptionHandler("/Error");
|
||||
app.UseHsts();
|
||||
}
|
||||
|
||||
// Localization IT
|
||||
var supportedCultures = new[] { new CultureInfo("it-IT") };
|
||||
app.UseRequestLocalization(new RequestLocalizationOptions
|
||||
{
|
||||
DefaultRequestCulture = new RequestCulture("it-IT"),
|
||||
SupportedCultures = supportedCultures,
|
||||
FallBackToParentCultures = false
|
||||
});
|
||||
CultureInfo.DefaultThreadCurrentCulture = CultureInfo.CreateSpecificCulture("it-IT");
|
||||
|
||||
app.UseForwardedHeaders(new ForwardedHeadersOptions
|
||||
{
|
||||
ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
|
||||
});
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
app.UseStaticFiles();
|
||||
app.UseRouting();
|
||||
|
||||
app.UseAuthentication();
|
||||
app.UseAuthorization();
|
||||
|
||||
app.MapControllers();
|
||||
app.MapBlazorHub();
|
||||
app.MapHealthChecksUI();
|
||||
app.MapHealthChecks("/health", new HealthCheckOptions
|
||||
{
|
||||
Predicate = _ => true,
|
||||
ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse
|
||||
});
|
||||
app.MapFallbackToPage("/_Host");
|
||||
|
||||
app.Run();
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
logger.Error(exception, "Stopped GMWS.UI program because of exception");
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
LogManager.Shutdown();
|
||||
}
|
||||
@@ -1,324 +0,0 @@
|
||||
using GWMS.Data;
|
||||
using GWMS.UI.Areas.Identity;
|
||||
using GWMS.UI.Data;
|
||||
using HealthChecks.UI.Client;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Components.Authorization;
|
||||
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.HttpOverrides;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Identity.UI.Services;
|
||||
using Microsoft.AspNetCore.Localization;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Diagnostics.HealthChecks;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using NLog;
|
||||
using NLog.Targets;
|
||||
using OpenTelemetry.Resources;
|
||||
using OpenTelemetry.Trace;
|
||||
using StackExchange.Redis;
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
|
||||
namespace GWMS.UI
|
||||
{
|
||||
public class Startup
|
||||
{
|
||||
#region Public Constructors
|
||||
|
||||
public Startup(IConfiguration configuration)
|
||||
{
|
||||
Configuration = configuration;
|
||||
}
|
||||
|
||||
#endregion Public Constructors
|
||||
|
||||
#region Public Properties
|
||||
|
||||
public IConfiguration Configuration { get; }
|
||||
|
||||
#endregion Public Properties
|
||||
|
||||
#region Public Methods
|
||||
|
||||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
||||
{
|
||||
|
||||
// aggiunt base URL x routing corretto
|
||||
app.UsePathBase(Configuration["RuntimeOpt:BaseAppPath"]);
|
||||
|
||||
if (env.IsDevelopment())
|
||||
{
|
||||
app.UseDeveloperExceptionPage();
|
||||
app.UseMigrationsEndPoint();
|
||||
}
|
||||
else
|
||||
{
|
||||
app.UseExceptionHandler("/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();
|
||||
}
|
||||
|
||||
// cultura IT...
|
||||
var supportedCultures = new[]{
|
||||
new CultureInfo("it-IT")
|
||||
};
|
||||
app.UseRequestLocalization(new RequestLocalizationOptions
|
||||
{
|
||||
DefaultRequestCulture = new RequestCulture("it-IT"),
|
||||
SupportedCultures = supportedCultures,
|
||||
FallBackToParentCultures = false
|
||||
});
|
||||
CultureInfo.DefaultThreadCurrentCulture = CultureInfo.CreateSpecificCulture("it-IT");
|
||||
|
||||
//// Registrazione Elmah:
|
||||
//// https://github.com/ElmahCore/ElmahCore
|
||||
//app.UseElmah();
|
||||
|
||||
// fix forwarders
|
||||
app.UseForwardedHeaders(new ForwardedHeadersOptions
|
||||
{
|
||||
ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
|
||||
});
|
||||
|
||||
app.UsePathBase(Configuration["BaseAppPath"]);
|
||||
|
||||
app.UseAuthentication();
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
app.UseStaticFiles();
|
||||
|
||||
app.UseRouting();
|
||||
|
||||
app.UseAuthentication();
|
||||
app.UseAuthorization();
|
||||
|
||||
app.UseEndpoints(endpoints =>
|
||||
{
|
||||
endpoints.MapControllers();
|
||||
endpoints.MapBlazorHub();
|
||||
endpoints.MapHealthChecksUI();
|
||||
endpoints.MapHealthChecks("/health", new HealthCheckOptions
|
||||
{
|
||||
Predicate = _ => true,
|
||||
ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse
|
||||
});
|
||||
endpoints.MapFallbackToPage("/_Host");
|
||||
});
|
||||
}
|
||||
|
||||
// This method gets called by the runtime. Use this method to add services to the container.
|
||||
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
// REDIS setup
|
||||
string connStringRedis = Configuration.GetConnectionString("Redis");
|
||||
string redisSrvAddr = "127.0.0.1";
|
||||
if (connStringRedis.Contains(":"))
|
||||
{
|
||||
redisSrvAddr = connStringRedis.Substring(0, connStringRedis.IndexOf(":"));
|
||||
}
|
||||
// avvio oggetto shared x redis...
|
||||
var redisMultiplexer = ConnectionMultiplexer.Connect(connStringRedis);
|
||||
// Add services x accesso dati
|
||||
services.AddSingleton<IConnectionMultiplexer>(redisMultiplexer);
|
||||
|
||||
// ====================================================================
|
||||
// Setup Tracing e Telemetria...
|
||||
// ====================================================================
|
||||
|
||||
// 1. Leggiamo la configurazione
|
||||
var otelEnabled = Configuration.GetValue<bool>("Otel:EnableTracing", false);
|
||||
var otelEndpoint = Configuration["Otel:Endpoint"];
|
||||
var otelDsn = Configuration["Otel:Dsn"];
|
||||
|
||||
if (otelEnabled)
|
||||
{
|
||||
// ====================================================================
|
||||
// SETUP OPENTELEMETRY BASE (Genera gli oggetti Activity)
|
||||
// Questo gira per i Livelli 1, 2 e 3.
|
||||
// ====================================================================
|
||||
var appVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version?.ToString() ?? "1.0.0";
|
||||
|
||||
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);
|
||||
|
||||
services.AddOpenTelemetry()
|
||||
.WithTracing(tracerProviderBuilder =>
|
||||
{
|
||||
tracerProviderBuilder
|
||||
.SetResourceBuilder(OpenTelemetry.Resources.ResourceBuilder.CreateDefault()
|
||||
.AddService(serviceName: "GWMS", serviceVersion: appVersion))
|
||||
.AddSource("GWMS.Data")
|
||||
.AddSource("GWMS.UI")
|
||||
.AddAspNetCoreInstrumentation(options => { options.Filter = ctx => !ctx.Request.Path.StartsWithSegments("/health"); })
|
||||
.AddHttpClientInstrumentation()
|
||||
.AddEntityFrameworkCoreInstrumentation()
|
||||
.AddRedisInstrumentation(redisMultiplexer);
|
||||
|
||||
// ====================================================================
|
||||
// ESPORTAZIONE DI RETE (Solo Livelli 1 e 2)
|
||||
// ====================================================================
|
||||
if (!string.IsNullOrWhiteSpace(otelEndpoint))
|
||||
{
|
||||
tracerProviderBuilder.AddOtlpExporter(options =>
|
||||
{
|
||||
options.Endpoint = new Uri(otelEndpoint);
|
||||
if (!string.IsNullOrWhiteSpace(otelDsn))
|
||||
{
|
||||
options.Headers = $"uptrace-dsn={otelDsn}";
|
||||
}
|
||||
options.Protocol = OpenTelemetry.Exporter.OtlpExportProtocol.Grpc;
|
||||
});
|
||||
}
|
||||
// Se otelEndpoint è vuoto (Livello 3), le tracce nascono e muoiono in RAM.
|
||||
});
|
||||
|
||||
// ====================================================================
|
||||
// ESPORTAZIONE NLOG REALTIME (Solo Livelli 1 e 2)
|
||||
// ====================================================================
|
||||
if (!string.IsNullOrWhiteSpace(otelEndpoint))
|
||||
{
|
||||
var otlpTarget = new OtlpTarget
|
||||
{
|
||||
Name = "UptraceRealtime",
|
||||
Endpoint = otelEndpoint,
|
||||
ServiceName = "GWMS.Data"
|
||||
};
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(otelDsn))
|
||||
{
|
||||
otlpTarget.Headers = $"uptrace-dsn={otelDsn}";
|
||||
}
|
||||
|
||||
var config = LogManager.Configuration ?? new NLog.Config.LoggingConfiguration();
|
||||
config.AddTarget(otlpTarget);
|
||||
config.AddRule(NLog.LogLevel.Info, NLog.LogLevel.Fatal, otlpTarget);
|
||||
LogManager.Configuration = config;
|
||||
LogManager.ReconfigExistingLoggers();
|
||||
|
||||
#if false
|
||||
logger.Info($"🚀 NLog & OTel attivi e in invio verso: {otelEndpoint}");
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
#if false
|
||||
logger.Info("ℹ️ OTel attivo (Local mode). Esportazione di rete disabilitata.");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
#if false
|
||||
// ====================================================================
|
||||
// LIVELLO 4: TUTTO SPENTO
|
||||
// ====================================================================
|
||||
logger.Info("⏸️ Telemetria e Tracing completamente disabilitati.");
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
// init info x DB
|
||||
string dbServerAddr = Configuration["DbConfig:Server"];
|
||||
string nKey = Configuration["DbConfig:nKey"];
|
||||
string sKey = Configuration["DbConfig:sKey"];
|
||||
DbConfig.InitDb(dbServerAddr, nKey, sKey);
|
||||
// inizializzo il DB e creo (se necessario) l'utente
|
||||
DbConfig.CheckUser(nKey, sKey);
|
||||
// verifico se serve applicazione migrazioni
|
||||
DbConfig.ExecMigrationMain();
|
||||
//DbConfig.ExecMigrationIdentity();
|
||||
|
||||
// altri parametri per check vari
|
||||
string connStringDB = DbConfig.CONNECTION_STRING;
|
||||
|
||||
// healthchecks
|
||||
services.AddHealthChecks()
|
||||
.AddMySql(connStringDB, "MySql instance")
|
||||
.AddAsyncCheck($"DB PING ({dbServerAddr})", () => Health.Checks.PingCheck(dbServerAddr))
|
||||
.AddAsyncCheck($"Redis PING ({redisSrvAddr})", () => Health.Checks.PingCheck(redisSrvAddr))
|
||||
.AddProcessAllocatedMemoryHealthCheck(512, "Max Process memory (<512MB)", failureStatus: HealthStatus.Degraded) // 512 MB max allocated memory
|
||||
.AddRedis(Configuration.GetConnectionString("Redis"), "Redis", failureStatus: HealthStatus.Degraded)
|
||||
.AddAsyncCheck($"MySql Root User", () => Health.Checks.DbUserRoot("MySql"))
|
||||
.AddAsyncCheck($"MySql Identity", () => Health.Checks.DbIdentity(DbConfig.DATABASE_NAME))
|
||||
.AddAsyncCheck($"MySql PlantLog", () => Health.Checks.DbPlantTable(DbConfig.DATABASE_NAME))
|
||||
;
|
||||
|
||||
services
|
||||
.AddHealthChecksUI(s =>
|
||||
{
|
||||
s.AddHealthCheckEndpoint("GWMS_Services", "health");
|
||||
s.SetEvaluationTimeInSeconds(60);
|
||||
s.SetMinimumSecondsBetweenFailureNotifications(120);
|
||||
s.SetApiMaxActiveRequests(5);
|
||||
s.SetHeaderText("GWMS Health Check Status");
|
||||
})
|
||||
.AddInMemoryStorage();
|
||||
|
||||
|
||||
// cookie applicazione da 14 gg (defaul) a 30
|
||||
services.ConfigureApplicationCookie(o =>
|
||||
{
|
||||
o.ExpireTimeSpan = TimeSpan.FromDays(30);
|
||||
o.SlidingExpiration = true;
|
||||
});
|
||||
// token di sicurezza dati a 3h
|
||||
services.Configure<DataProtectionTokenProviderOptions>(o =>
|
||||
o.TokenLifespan = TimeSpan.FromHours(3));
|
||||
|
||||
// abilitazione x email management con MailKit
|
||||
services.AddTransient<IEmailSender, MailKitEmailSender>();
|
||||
services.Configure<MailKitEmailSenderOptions>(options =>
|
||||
{
|
||||
options.Host_Address = Configuration["ExternalProviders:MailKit:SMTP:Address"];
|
||||
options.Host_Port = Convert.ToInt32(Configuration["ExternalProviders:MailKit:SMTP:Port"]);
|
||||
options.Host_Username = Configuration["ExternalProviders:MailKit:SMTP:Account"];
|
||||
options.Host_Password = Configuration["ExternalProviders:MailKit:SMTP:Password"];
|
||||
options.Sender_EMail = Configuration["ExternalProviders:MailKit:SMTP:SenderEmail"];
|
||||
options.Sender_Name = Configuration["ExternalProviders:MailKit:SMTP:SenderName"];
|
||||
});
|
||||
|
||||
|
||||
// setup MySql
|
||||
var serverVersion = DbConfig.MysqlServerVersion(connStringDB);
|
||||
services.AddDbContext<UserIdentityDbContext>(options =>
|
||||
options.UseMySql(connStringDB, serverVersion));
|
||||
|
||||
// identity management
|
||||
services.AddDefaultIdentity<IdentityUser>(options => options.SignIn.RequireConfirmedAccount = true)
|
||||
.AddRoles<IdentityRole>()
|
||||
.AddEntityFrameworkStores<UserIdentityDbContext>();
|
||||
|
||||
|
||||
|
||||
//// Elmah
|
||||
//services.AddElmah();
|
||||
//string elmaConn = "Data Source=SQL2016DEV;Initial Catalog=Elmah;User ID=sa;Password=keyhammer16;integrated security=False;MultipleActiveResultSets=True;App=SHERPA.BBM;";
|
||||
//services.AddElmah<SqlErrorLog>(options =>
|
||||
//{
|
||||
// options.ConnectionString = elmaConn;
|
||||
//});
|
||||
|
||||
services.AddLocalization();
|
||||
|
||||
services.AddRazorPages();
|
||||
services.AddServerSideBlazor();
|
||||
|
||||
services.AddScoped<AuthenticationStateProvider, RevalidatingIdentityAuthenticationStateProvider<IdentityUser>>();
|
||||
services.AddDatabaseDeveloperPageExceptionFilter();
|
||||
services.AddSingleton<IConfiguration>(Configuration);
|
||||
|
||||
services.AddScoped<GWMSDataService>();
|
||||
services.AddScoped<MessageService>();
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,7 @@ $FileManIn="..\Resources\manifest-original.xml"
|
||||
$FileManOut="..\Resources\manifest.xml"
|
||||
$FileCLogIn="..\Resources\ChangeLog-original.html"
|
||||
$FileCLogOut="..\Resources\ChangeLog.html"
|
||||
$MajMin="1.0."
|
||||
$MajMin="1.1."
|
||||
$currentDate = get-date -format yyMM;
|
||||
$currentTime = get-date -format ddHH;
|
||||
$find = "<Version>(.|\n)*?</Version>";
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<body>
|
||||
<i>GWMS - Gas Warehouse Management System</i>
|
||||
<h4>Versione: 1.0.2603.0407</h4>
|
||||
<h4>Versione: 1.1.2603.0407</h4>
|
||||
<br /> Note di rilascio:
|
||||
<ul>
|
||||
<li>
|
||||
|
||||
@@ -1 +1 @@
|
||||
1.0.2603.0407
|
||||
1.1.2603.0407
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<item>
|
||||
<version>1.0.2603.0407</version>
|
||||
<version>1.1.2603.0407</version>
|
||||
<url>http://nexus.steamware.net/repository/SWS/GWMS/stable/0/GWMS.UI.zip</url>
|
||||
<changelog>http://nexus.steamware.net/repository/SWS/GWMS/stable/0/ChangeLog.html</changelog>
|
||||
<mandatory>false</mandatory>
|
||||
|
||||
Reference in New Issue
Block a user