Skip to content

Commit

Permalink
Bump version to v3.5.0
Browse files Browse the repository at this point in the history
* Migrate startup from Host.CreateDefaultBuilder to WebApplicationBuilder
   * ASP.NET Core 3.1 used the Generic Host for Startup. This is compatible with NET6.0. NET6.0 now recommends the new minimal hosting model with WebApplicationBuilder.
   * Most configuration now happens in WebApplicationBuilder and static helper classe

* Fix NLog.{Environment}.config:
Add to targets: keepFileOpen="true" openFileCacheTimeout="5" concurrentWrites="true"
This will stop log files to be blocked while the app is running

* Update to PiranhaCMS 10.3.0
* Update referenced packages
   * Microsoft.Extensions.Logging.Abstractions 7.0.0
   * NLog.Web.AspNetCore 5.2.1
   * EPPlus 6.1.2
   * MailKit 3.5.0
   * Microsoft.Data.SqlClient 5.1.0
   * Microsoft.EntityFrameworkCore 7.0.2
   * Microsoft.EntityFrameworkCore.Tools 7.0.2
  • Loading branch information
axunonb committed Feb 13, 2023
1 parent 63e9f39 commit 46b32af
Show file tree
Hide file tree
Showing 6 changed files with 206 additions and 203 deletions.
14 changes: 7 additions & 7 deletions ClubSite/Areas/Manager/Pages/Login.cshtml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
@page "~/manager/login"
@model Piranha.Manager.LocalAuth.Areas.Manager.Pages.LoginModel
@inject Piranha.Manager.ManagerLocalizer Localizer
@inject ManagerLocalizer Localizer
@{
Layout = null;
var module = Piranha.App.Modules.Get<Piranha.Manager.Module>();
var prerelease = Piranha.Utils.IsPreRelease(typeof(Piranha.Manager.Module).Assembly) ? "pre-release" : "";
var module = Piranha.App.Modules.Get<Module>();
var preRelease = Piranha.Utils.IsPreRelease(typeof(Module).Assembly) ? "pre-release" : "";
}
<!doctype html>
<html lang="en" style="min-height:100%">
Expand All @@ -20,8 +20,8 @@

<title>@Localizer.General["Login"]</title>
</head>
<body id="login" class="@prerelease">
@if (!string.IsNullOrEmpty(prerelease))
<body id="login" class="@preRelease">
@if (!string.IsNullOrEmpty(preRelease))
{
<div class="pre-release">Pre-release</div>
}
Expand All @@ -33,7 +33,7 @@
<div class="logo"></div>
<p class="banner">
Piranha CMS
<small>@Localizer.General["Version"] @Piranha.Utils.GetAssemblyVersion(typeof(Piranha.Manager.Module).Assembly)</small>
<small>@Localizer.General["Version"] @Piranha.Utils.GetAssemblyVersion(typeof(Module).Assembly)</small>
</p>
</div>

Expand All @@ -58,7 +58,7 @@
</div>
</form>
<div class="text-center" style="margin-top: 3rem">
<p style="text-transform: none; font-size: 1rem; margin-top: 0; color: gray"><a href="https://github.com/axuno/ClubSite" target="_blank" style="color: gray" onmouseover="this.style.color = 'gray'" onmouseout="this.style.color = 'gray'">axuno ClubSite, @Localizer.General["Version"] @Piranha.Utils.GetAssemblyVersion(typeof(ClubSite.Startup).Assembly)</a></p>
<p style="text-transform: none; font-size: 1rem; margin-top: 0; color: gray"><a href="https://github.com/axuno/ClubSite" target="_blank" style="color: gray" onmouseover="this.style.color = 'gray'" onmouseout="this.style.color = 'gray'">axuno ClubSite, @Localizer.General["Version"] @Piranha.Utils.GetAssemblyVersion(typeof(ClubSite.Program).Assembly)</a></p>
<small style="text-transform: none; font-size: 0.8rem; margin-top: 0; color: gray">
Design und Realisierung:<br/>
Norbert Bietsch, <a href="https://axuno.net/" target="_blank" style="color: gray" onmouseover="this.style.color = 'gray'" onmouseout="this.style.color = 'gray'">axuno gemeinnützige GmbH</a>
Expand Down
38 changes: 19 additions & 19 deletions ClubSite/ClubSite.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
<Version>3.4.0</Version>
<Version>3.5.0</Version>
<Authors>axuno gGmbH</Authors>
<Description>The source code for https://www.volleyballclub.de/</Description>
<CurrentYear>$([System.DateTime]::Now.ToString(yyyy))</CurrentYear>
Expand All @@ -13,28 +13,28 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="EPPlus" Version="6.0.8" />
<PackageReference Include="MailKit" Version="3.4.1" />
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.10" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.10">
<PackageReference Include="EPPlus" Version="6.1.2" />
<PackageReference Include="MailKit" Version="3.5.0" />
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.2" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="6.0.10" />
<PackageReference Include="NLog.Web.AspNetCore" Version="5.1.4" />
<PackageReference Include="Piranha" Version="10.2.0" />
<PackageReference Include="Piranha.AspNetCore" Version="10.2.0" />
<PackageReference Include="Piranha.AspNetCore.Identity" Version="10.2.0" />
<PackageReference Include="Piranha.AspNetCore.Identity.SQLServer" Version="10.2.0" />
<PackageReference Include="Piranha.AspNetCore.SimpleSecurity" Version="10.2.0" />
<PackageReference Include="Piranha.AttributeBuilder" Version="10.2.0" />
<PackageReference Include="Piranha.Data.EF.SQLServer" Version="10.2.0" />
<PackageReference Include="Piranha.ImageSharp" Version="10.2.0" />
<PackageReference Include="Piranha.Local.FileStorage" Version="10.2.0" />
<PackageReference Include="Piranha.Manager" Version="10.2.0" />
<PackageReference Include="Piranha.Manager.TinyMCE" Version="10.2.0" />
<PackageReference Include="NLog.Web.AspNetCore" Version="5.2.1" />
<PackageReference Include="Piranha" Version="10.3.0" />
<PackageReference Include="Piranha.AspNetCore" Version="10.3.0" />
<PackageReference Include="Piranha.AspNetCore.Identity" Version="10.3.0" />
<PackageReference Include="Piranha.AspNetCore.Identity.SQLServer" Version="10.3.0" />
<PackageReference Include="Piranha.AspNetCore.SimpleSecurity" Version="10.3.0" />
<PackageReference Include="Piranha.AttributeBuilder" Version="10.3.0" />
<PackageReference Include="Piranha.Data.EF.SQLServer" Version="10.3.0" />
<PackageReference Include="Piranha.ImageSharp" Version="10.3.0" />
<PackageReference Include="Piranha.Local.FileStorage" Version="10.3.0" />
<PackageReference Include="Piranha.Manager" Version="10.3.0" />
<PackageReference Include="Piranha.Manager.TinyMCE" Version="10.3.0" />
</ItemGroup>

<ItemGroup>
Expand Down
6 changes: 3 additions & 3 deletions ClubSite/Configuration/NLog.Development.config
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
<!-- the targets to write to -->
<targets async="true">
<!-- write logs to file ** ${var:logDirectory} is set in Program.Main() -->
<target xsi:type="File" name="allfile" fileName="${var:logDirectory}logs\nlog-all-${shortdate}.log"
<target xsi:type="File" name="allfile" fileName="${var:logDirectory}logs\nlog-all-${shortdate}.log" keepFileOpen="true" openFileCacheTimeout="5" concurrentWrites="true"
layout="${aspnet-request:header=JSNLog-RequestId:whenEmpty=${aspnet-TraceIdentifier}} ${longdate}|${event-properties:item=EventId.Id}|${uppercase:${level}}|${logger}|${message} ${exception:format=ToString,StackTrace}" />

<!-- "not found" file log, only own logs. -->
<target xsi:type="File" name="notFoundFile-web" fileName="${var:logDirectory}logs\nlog-not-found-${shortdate}.log"
<target xsi:type="File" name="notFoundFile-web" fileName="${var:logDirectory}logs\nlog-not-found-${shortdate}.log" keepFileOpen="true" openFileCacheTimeout="5" concurrentWrites="true"
layout="${aspnet-request:header=JSNLog-RequestId:whenEmpty=${aspnet-TraceIdentifier}} ${longdate}|${event-properties:item=EventId.Id}|${uppercase:${level}}|${logger}|${message}" />

<!-- another file log, only own logs. -->
<target xsi:type="File" name="ownFile-web" fileName="${var:logDirectory}logs\nlog-own-${shortdate}.log"
<target xsi:type="File" name="ownFile-web" fileName="${var:logDirectory}logs\nlog-own-${shortdate}.log" keepFileOpen="true" openFileCacheTimeout="5" concurrentWrites="true"
layout="${aspnet-request:header=JSNLog-RequestId:whenEmpty=${aspnet-TraceIdentifier}} ${longdate}|${event-properties:item=EventId.Id}|${uppercase:${level}}|${logger}|${message} ${exception:format=ToString,StackTrace}${newline} |url: ${aspnet-request-url}|action: ${aspnet-mvc-action}" />

<!-- write to void i.e. just remove -->
Expand Down
6 changes: 3 additions & 3 deletions ClubSite/Configuration/NLog.Production.config
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
<!-- the targets to write to -->
<targets async="true">
<!-- write logs to file ** ${var:logDirectory} is set in Program.Main() -->
<target xsi:type="File" name="allfile" fileName="${var:logDirectory}logs\nlog-all-${shortdate}.log"
<target xsi:type="File" name="allfile" fileName="${var:logDirectory}logs\nlog-all-${shortdate}.log" keepFileOpen="true" openFileCacheTimeout="5" concurrentWrites="true"
layout="${aspnet-request:header=JSNLog-RequestId:whenEmpty=${aspnet-TraceIdentifier}} ${longdate}|${event-properties:item=EventId.Id}|${uppercase:${level}}|${logger}|${message} ${exception:format=ToString,StackTrace}" />

<!-- "not found" file log, only own logs. -->
<target xsi:type="File" name="notFoundFile-web" fileName="${var:logDirectory}logs\nlog-not-found-${shortdate}.log"
<target xsi:type="File" name="notFoundFile-web" fileName="${var:logDirectory}logs\nlog-not-found-${shortdate}.log" keepFileOpen="true" openFileCacheTimeout="5" concurrentWrites="true"
layout="${aspnet-request:header=JSNLog-RequestId:whenEmpty=${aspnet-TraceIdentifier}} ${longdate}|${event-properties:item=EventId.Id}|${uppercase:${level}}|${logger}|${message}" />

<!-- another file log, only own logs. -->
<target xsi:type="File" name="ownFile-web" fileName="${var:logDirectory}logs\nlog-own-${shortdate}.log"
<target xsi:type="File" name="ownFile-web" fileName="${var:logDirectory}logs\nlog-own-${shortdate}.log" keepFileOpen="true" openFileCacheTimeout="5" concurrentWrites="true"
layout="${aspnet-request:header=JSNLog-RequestId:whenEmpty=${aspnet-TraceIdentifier}} ${longdate}|${event-properties:item=EventId.Id}|${uppercase:${level}}|${logger}|${message} ${exception:format=ToString,StackTrace}${newline} |url: ${aspnet-request-url}|action: ${aspnet-mvc-action}" />

<!-- write to void i.e. just remove -->
Expand Down
107 changes: 60 additions & 47 deletions ClubSite/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@

using System;
using System.IO;
using Microsoft.AspNetCore;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using NLog.Extensions.Logging;
using NLog.Web;

namespace ClubSite;
Expand All @@ -22,7 +25,7 @@ public class Program
/// </summary>
public const string ConfigurationFolder = "Configuration";

public static void Main(string[] args)
public static async Task Main(string[] args)
{
// NLog: setup the logger first to catch all errors
var currentDir = Directory.GetCurrentDirectory();
Expand All @@ -31,15 +34,32 @@ public static void Main(string[] args)
.GetCurrentClassLogger();

// Allows for <target name="file" xsi:type="File" fileName = "${var:logDirectory}logfile.log"... >
NLog.LogManager.Configuration.Variables["logDirectory"] = currentDir + Path.DirectorySeparatorChar;
NLog.LogManager.Configuration.Variables["logDirectory"] = $"{currentDir}{Path.DirectorySeparatorChar}";

try
{
logger.Trace($"Configuration of {nameof(WebHost)} starting.");
// http://zuga.net/articles/cs-how-to-determine-if-a-program-process-or-file-is-32-bit-or-64-bit/
logger.Info($"This app runs as {(System.Environment.Is64BitProcess ? "64-bit" : "32-bit")} process.\n\n");
logger.Trace($"Configuration of {nameof(Microsoft.AspNetCore.WebHost)} starting.");
logger.Info($"This app runs as {(Environment.Is64BitProcess ? "64-bit" : "32-bit")} process.\n\n");

CreateHostBuilder(args).Build().Run();
var builder = SetupBuilder(args);

var loggingConfig = builder.Configuration.GetSection("Logging");
builder.Logging.ClearProviders();
// Enable NLog as logging provider for Microsoft.Extension.Logging
builder.Logging.AddNLog(loggingConfig);
NLogBuilder.ConfigureNLog(Path.Combine(builder.Environment.ContentRootPath, ConfigurationFolder,
$"NLog.{builder.Environment.EnvironmentName}.config"));

builder.WebHost.ConfigureServices(WebAppStartup.ConfigureServices);

var app = builder.Build();

builder.WebHost.ConfigureAppConfiguration((context, confBuilder) =>
{
WebAppStartup.Configure(app, app.Services.GetRequiredService<ILoggerFactory>());
});

await app.RunAsync();
}
catch (Exception e)
{
Expand All @@ -48,52 +68,45 @@ public static void Main(string[] args)
}
finally
{
// Ensure to flush and stop internal timers/threads before application-exit (Avoid segmentation fault on Linux)
// Ensure to flush and stop internal timers/threads before application-exit (avoid segmentation fault on Linux)
NLog.LogManager.Shutdown();
}
}

public static IHostBuilder CreateHostBuilder(string[] args)
public static WebApplicationBuilder SetupBuilder(string[] args)
{
return Host.CreateDefaultBuilder(args)
.ConfigureAppConfiguration((hostingContext, config) =>
{
var configPath = Path.Combine(hostingContext.HostingEnvironment.ContentRootPath,
ConfigurationFolder);
config.SetBasePath(configPath)
.AddJsonFile("appsettings.json", false, true)
.AddJsonFile($"appsettings.{hostingContext.HostingEnvironment.EnvironmentName}.json", true,
true)
.AddJsonFile(@"credentials.json", false, true)
.AddJsonFile($"credentials.{hostingContext.HostingEnvironment.EnvironmentName}.json", false,
true)
.AddEnvironmentVariables()
.AddCommandLine(args);
var builder = WebApplication.CreateBuilder(new WebApplicationOptions
{
Args = args,
ApplicationName = typeof(Program).Assembly.GetName().Name, // don't use Assembly.Fullname
ContentRootPath = Directory.GetCurrentDirectory(),
WebRootPath = "wwwroot"
});

var absoluteConfigurationPath = Path.Combine(builder.Environment.ContentRootPath,
ConfigurationFolder);

var secretsFolder = Path.Combine(configPath, @$"..{Path.DirectorySeparatorChar}..{Path.DirectorySeparatorChar}..{Path.DirectorySeparatorChar}Secrets");
if (hostingContext.HostingEnvironment.IsDevelopment())
{
if (!Directory.Exists(secretsFolder))
throw new DirectoryNotFoundException("Secrets folder not found");
config.AddJsonFile(Path.Combine(secretsFolder, @"credentials.json"), false);
config.AddJsonFile(
Path.Combine(secretsFolder,
$"credentials.{hostingContext.HostingEnvironment.EnvironmentName}.json"), false);
}
builder.Configuration.SetBasePath(absoluteConfigurationPath)
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.AddJsonFile($"appsettings.{builder.Environment.EnvironmentName}.json",
optional: true, reloadOnChange: true)
.AddJsonFile(@"credentials.json", optional: false, reloadOnChange: true)
.AddJsonFile($"credentials.{builder.Environment.EnvironmentName}.json",
optional: false, reloadOnChange: true)
.AddEnvironmentVariables()
.AddCommandLine(args);

NLogBuilder.ConfigureNLog(Path.Combine(configPath,
$"NLog.{hostingContext.HostingEnvironment.EnvironmentName}.config"));
})
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
})
.ConfigureLogging((hostingContext, logging) =>
{
logging.ClearProviders();
// Note: This logging configuration overrides any call to SetMinimumLevel!
logging.AddConfiguration(hostingContext.Configuration.GetSection("Logging"));
})
.UseNLog(); // NLog: Setup NLog for dependency injection;
if (builder.Environment.IsDevelopment())
{
var secretsFolder = Path.Combine(builder.Environment.ContentRootPath, ConfigurationFolder, @$"..{Path.DirectorySeparatorChar}..{Path.DirectorySeparatorChar}..{Path.DirectorySeparatorChar}Secrets");
if (!Directory.Exists(secretsFolder)) throw new DirectoryNotFoundException("Secrets folder not found");
builder.Configuration.AddJsonFile(Path.Combine(secretsFolder, @"credentials.json"), false);
builder.Configuration.AddJsonFile(Path.Combine(secretsFolder, $"credentials.{builder.Environment.EnvironmentName}.json"), false);
}

// Use static web assets from League (and other referenced projects or packages)
builder.WebHost.UseStaticWebAssets();

return builder;
}
}
Loading

0 comments on commit 46b32af

Please sign in to comment.