Opstart zonder mailconfiguratie getest voor alle hosts, Website__LogLevel zonder punt in de naam
Oorzaak 502 op ASF test: Email__Smtp__Host stond al in de omgeving maar App__PublicBaseUrl nog niet; de startvalidatie weigert zo'n halve mailconfiguratie. Een host zonder enige mailinstelling start gewoon: nu voor master, slave, SlpSoftware en ASF getest. Website__LogLevel vervangt de Logging__LogLevel__SlpModularCms.Website-variabele, waarvan systemd de naam met punt negeert. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -22,8 +22,20 @@ public static class PrerenderedSiteExtensions
|
||||
{
|
||||
services.AddOptions<WebsiteOptions>()
|
||||
.Bind(configuration.GetSection(WebsiteOptions.SectionName))
|
||||
.Validate(o => WebsiteOptions.IsValidLogLevel(o.LogLevel),
|
||||
"Website:LogLevel must be a log level name (Trace, Debug, Information, Warning, Error, Critical, None) or empty.")
|
||||
.ValidateOnStart();
|
||||
|
||||
// Website:LogLevel (env: Website__LogLevel) sets the level of the website's logger category. It exists
|
||||
// because Logging__LogLevel__SlpModularCms.Website has a dot in its name, which systemd's
|
||||
// EnvironmentFile does not accept.
|
||||
var configuredLevel = configuration[$"{WebsiteOptions.SectionName}:LogLevel"];
|
||||
if (!string.IsNullOrWhiteSpace(configuredLevel)
|
||||
&& Enum.TryParse<LogLevel>(configuredLevel.Trim(), ignoreCase: true, out var level))
|
||||
{
|
||||
services.AddLogging(logging => logging.AddFilter(PrerenderedSiteMiddleware.LoggerCategory, level));
|
||||
}
|
||||
|
||||
// Presence of the marker switches on the full security-header set for website responses.
|
||||
services.AddSingleton<WebsiteHostingMarker>();
|
||||
|
||||
|
||||
@@ -10,4 +10,15 @@ public sealed class WebsiteOptions
|
||||
/// <c>X-Robots-Tag: noindex, nofollow</c> and <c>/robots.txt</c> disallows everything.
|
||||
/// </summary>
|
||||
public bool NoIndex { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Log level of the website's own logger category (<c>SlpModularCms.Website</c>: 301s and 404s at
|
||||
/// Information), set as <c>Website__LogLevel</c>. Needed because the usual per-category override
|
||||
/// <c>Logging__LogLevel__SlpModularCms.Website</c> cannot be set from a systemd EnvironmentFile (a
|
||||
/// variable name containing a dot is ignored there). Empty = leave it to <c>Logging:LogLevel</c>.
|
||||
/// </summary>
|
||||
public string? LogLevel { get; set; }
|
||||
|
||||
public static bool IsValidLogLevel(string? value) =>
|
||||
string.IsNullOrWhiteSpace(value) || Enum.TryParse<Microsoft.Extensions.Logging.LogLevel>(value.Trim(), ignoreCase: true, out _);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user