diff --git a/build/run/ApiSystem.bat b/build/run/ApiSystem.bat new file mode 100644 index 0000000000..d1f443674b --- /dev/null +++ b/build/run/ApiSystem.bat @@ -0,0 +1,4 @@ +@echo off + +PUSHD %~dp0..\.. +set servicepath=%cd%\common\services\ASC.ApiSystem\bin\Debug\ASC.ApiSystem.exe urls=http://0.0.0.0:5010 $STORAGE_ROOT=%cd%\Data log:dir=%cd%\Logs log:name=apisystem pathToConf=%cd%\config core:products:folder=%cd%\products \ No newline at end of file diff --git a/common/services/ASC.ApiSystem/GlobalUsings.cs b/common/services/ASC.ApiSystem/GlobalUsings.cs index ef23f79860..403c00bacb 100644 --- a/common/services/ASC.ApiSystem/GlobalUsings.cs +++ b/common/services/ASC.ApiSystem/GlobalUsings.cs @@ -101,3 +101,5 @@ global using Microsoft.Extensions.Logging; global using Microsoft.Extensions.Options; global using Newtonsoft.Json.Linq; + +global using NLog; \ No newline at end of file diff --git a/common/services/ASC.ApiSystem/Models/TenantModel.cs b/common/services/ASC.ApiSystem/Models/TenantModel.cs index f25172918f..5083a5e1c6 100644 --- a/common/services/ASC.ApiSystem/Models/TenantModel.cs +++ b/common/services/ASC.ApiSystem/Models/TenantModel.cs @@ -56,7 +56,7 @@ public class TenantModel : IModel public string Module { get; set; } //todo: delete after www update - [StringLength(Web.Core.Utility.PasswordSettings.MaxLength)] + [StringLength(PasswordSettings.MaxLength)] public string Password { get; set; } public string PasswordHash { get; set; } diff --git a/common/services/ASC.ApiSystem/Program.cs b/common/services/ASC.ApiSystem/Program.cs index 13e2ba0802..6f4fc3bcd9 100644 --- a/common/services/ASC.ApiSystem/Program.cs +++ b/common/services/ASC.ApiSystem/Program.cs @@ -24,27 +24,61 @@ // content are licensed under the terms of the Creative Commons Attribution-ShareAlike 4.0 // International. See the License terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode + var options = new WebApplicationOptions { Args = args, ContentRootPath = WindowsServiceHelpers.IsWindowsService() ? AppContext.BaseDirectory : default }; -var builder = WebApplication.CreateBuilder(options); - -builder.Host.ConfigureDefault(); +var builder = WebApplication.CreateBuilder(options); builder.Configuration.AddDefaultConfiguration(builder.Environment) .AddApiSystemConfiguration(builder.Environment) .AddEnvironmentVariables() .AddCommandLine(args); -var startup = new Startup(builder.Configuration, builder.Environment); +var logger = LogManager.Setup() + .SetupExtensions(s => + { + s.RegisterLayoutRenderer("application-context", (logevent) => AppName); + }) + .LoadConfiguration(builder.Configuration, builder.Environment) + .GetLogger(typeof(Startup).Namespace); -startup.ConfigureServices(builder.Services); +try +{ + logger.Info("Configuring web host ({applicationContext})...", AppName); + builder.Host.ConfigureDefault(); -var app = builder.Build(); + var startup = new Startup(builder.Configuration, builder.Environment); -startup.Configure(app, app.Environment); + startup.ConfigureServices(builder.Services); -await app.RunAsync(); + var app = builder.Build(); + + startup.Configure(app, app.Environment); + + logger.Info("Starting web host ({applicationContext})...", AppName); + await app.RunWithTasksAsync(); +} +catch (Exception ex) +{ + if (logger != null) + { + logger.Error(ex, "Program terminated unexpectedly ({applicationContext})!", AppName); + } + + throw; +} +finally +{ + // Ensure to flush and stop internal timers/threads before application-exit (Avoid segmentation fault on Linux) + LogManager.Shutdown(); +} + +public partial class Program +{ + public static string Namespace = typeof(Startup).Namespace; + public static string AppName = Namespace.Substring(Namespace.LastIndexOf('.') + 1); +} \ No newline at end of file