72 lines
2.6 KiB
C#
72 lines
2.6 KiB
C#
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.Hosting;
|
|
using Microsoft.Extensions.Logging;
|
|
using NLog;
|
|
using NLog.Web;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace GWMS.UI
|
|
{
|
|
public class Program
|
|
{
|
|
#region Public Methods
|
|
|
|
public static IHostBuilder CreateHostBuilder(string[] args) =>
|
|
Host.CreateDefaultBuilder(args)
|
|
.ConfigureWebHostDefaults(webBuilder =>
|
|
{
|
|
webBuilder.UseStartup<Startup>();
|
|
})
|
|
.ConfigureLogging(logging =>
|
|
{
|
|
logging.ClearProviders();
|
|
#if DEBUG
|
|
//logging.SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Debug);
|
|
logging.SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Information);
|
|
#else
|
|
logging.SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Warning);
|
|
#endif
|
|
})
|
|
.UseNLog();
|
|
|
|
public static void Main(string[] args)
|
|
{
|
|
// inclusione NLog:
|
|
// https://github.com/NLog/NLog/wiki/Getting-started-with-ASP.NET-Core-5
|
|
// https://codewithmukesh.com/blog/logging-with-nlog-in-aspnet-core/
|
|
//var logger = NLogBuilder.ConfigureNLog("NLog.config").GetCurrentClassLogger();
|
|
var logger = LogManager.Setup().LoadConfigurationFromAppSettings().GetCurrentClassLogger();
|
|
|
|
#if false
|
|
// sistemazione NLog da codice...
|
|
LogManager.Setup().LoadConfiguration(builder =>
|
|
{
|
|
builder.ForLogger().FilterMinLevel(NLog.LogLevel.Debug).WriteToConsole(layout: "${longdate} | ${uppercase:${level}} | ${logger:shortName=false} | ${message}");
|
|
builder.ForLogger().FilterMinLevel(NLog.LogLevel.Debug).WriteToFile(layout: "${longdate} | ${uppercase:${level}} | ${logger:shortName=false} | ${message}", fileName: "${basedir}/logs/App_${shortdate}.log");
|
|
});
|
|
var logger = LogManager.GetCurrentClassLogger();
|
|
#endif
|
|
|
|
try
|
|
{
|
|
logger.Info("GMWS.UI Application Starting Up");
|
|
CreateHostBuilder(args).Build().Run();
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
logger.Error(exception, "Stopped GMWS.UI program because of exception");
|
|
throw;
|
|
}
|
|
finally
|
|
{
|
|
LogManager.Shutdown();
|
|
}
|
|
}
|
|
|
|
#endregion Public Methods
|
|
}
|
|
} |