ApiSystem: log, service

This commit is contained in:
pavelbannov 2022-10-17 18:24:50 +03:00
parent c938a98d00
commit 502aac91b1
4 changed files with 49 additions and 9 deletions

4
build/run/ApiSystem.bat Normal file
View File

@ -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

View File

@ -101,3 +101,5 @@ global using Microsoft.Extensions.Logging;
global using Microsoft.Extensions.Options;
global using Newtonsoft.Json.Linq;
global using NLog;

View File

@ -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; }

View File

@ -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);
}