Added base NLog configuration
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
<PackageReference Include="Microsoft.AspNetCore" Version="2.2.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
|
||||
<PackageReference Include="NLog" Version="5.2.8" />
|
||||
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.8" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="6.5.0" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore.Filters" Version="8.0.0" />
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
|
||||
<targets>
|
||||
<target name="logfile" xsi:type="File" fileName="file.txt" />
|
||||
<target name="logfile" xsi:type="File" fileName="Logs/application.txt" />
|
||||
<target name="logconsole" xsi:type="Console" />
|
||||
</targets>
|
||||
|
||||
|
||||
@@ -1,15 +1,22 @@
|
||||
using System;
|
||||
using Microsoft.OpenApi.Models;
|
||||
using NLog;
|
||||
using BasicDotnetTemplate.MainProject.Models.Settings;
|
||||
using BasicDotnetTemplate.MainProject.Utils;
|
||||
|
||||
namespace BasicDotnetTemplate.MainProject;
|
||||
internal static class Program
|
||||
{
|
||||
private static readonly NLog.Logger Logger = NLog.LogManager.GetCurrentClassLogger();
|
||||
|
||||
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
Logger.Info("[Program][Main] Start building");
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
Logger.Info("[Program][Main] Creating configuration");
|
||||
|
||||
var _configuration = new ConfigurationBuilder()
|
||||
.SetBasePath(System.AppDomain.CurrentDomain.BaseDirectory)
|
||||
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
|
||||
@@ -23,9 +30,14 @@ internal static class Program
|
||||
PrivateSettings privateSettings = new PrivateSettings();
|
||||
_configuration.GetSection("PrivateSettings").Bind(privateSettings);
|
||||
|
||||
|
||||
Logger.Info("[Program][Main] Building settings");
|
||||
|
||||
builder.Services.Configure<AppSettings>(_configuration.GetSection("AppSettings"));
|
||||
builder.Services.Configure<PrivateSettings>(_configuration.GetSection("PrivateSettings"));
|
||||
|
||||
Logger.Info("[Program][Main] Adding services");
|
||||
|
||||
builder.Services.AddAuthentication();
|
||||
builder.Services.AddAuthorization();
|
||||
|
||||
@@ -37,6 +49,8 @@ internal static class Program
|
||||
appSettings.PrivateSettings = privateSettings;
|
||||
_configuration.GetSection("AppSettings").Bind(appSettings);
|
||||
|
||||
Logger.Info("[Program][Main] Initializing swagger doc");
|
||||
|
||||
OpenApiInfo openApiInfo = new()
|
||||
{
|
||||
Version = appSettings.Settings?.Version,
|
||||
@@ -99,7 +113,13 @@ internal static class Program
|
||||
});
|
||||
}
|
||||
|
||||
Logger.Info("[Program][Main] Launching app");
|
||||
|
||||
app.Run();
|
||||
|
||||
Logger.Info("[Program][Main] Shutting down logger");
|
||||
|
||||
NLog.LogManager.Shutdown(); // Flush and close down internal threads and timers
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user