66 lines
2.7 KiB
C#
66 lines
2.7 KiB
C#
|
using Microsoft.AspNetCore;
|
|||
|
using Microsoft.AspNetCore.Hosting;
|
|||
|
using Microsoft.Extensions.Configuration;
|
|||
|
using Microsoft.Extensions.Hosting;
|
|||
|
using Microsoft.Extensions.Logging;
|
|||
|
using NLog.Web;
|
|||
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using System.Threading.Tasks;
|
|||
|
|
|||
|
namespace Traffic.Api
|
|||
|
{
|
|||
|
public class Program
|
|||
|
{
|
|||
|
//Trace 0 LogTrace() Logs messages only for tracing purposes for the developers.
|
|||
|
// <20><><EFBFBD><EFBFBD> Log <20>q<EFBFBD>`<60>Ω<EFBFBD><CEA9>}<7D>o<EFBFBD><6F><EFBFBD>q<EFBFBD>A<EFBFBD><41><EFBFBD>}<7D>o<EFBFBD>H<EFBFBD><48><EFBFBD>ˬd<CBAC><64><EFBFBD>ƨϥΡA<CEA1>i<EFBFBD><69><EFBFBD>|<7C>]<5D>t<EFBFBD>@<40>DZb<C7B1><62><EFBFBD>K<EFBFBD>X<EFBFBD><58><EFBFBD>ӷP<D3B7><50><EFBFBD>ơA<C6A1><41><EFBFBD>A<EFBFBD>X<EFBFBD>]<5D><><EFBFBD><EFBFBD><EFBFBD>ӥX<D3A5>{<7B>b<EFBFBD><62><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD> Log <20><><EFBFBD>C (<28>w<EFBFBD>]<5D><><EFBFBD>|<7C><><EFBFBD>X)
|
|||
|
|
|||
|
//Debug 1 LogDebug() Logs messages for short-term debugging purposes. <20>w<EFBFBD>]<5D><><EFBFBD>|<7C><><EFBFBD>X
|
|||
|
// <20>o<EFBFBD><6F><EFBFBD><EFBFBD><EFBFBD><EFBFBD> Log <20>O<EFBFBD><4F><EFBFBD>F<EFBFBD>b<EFBFBD><62><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ұ<EFBFBD><D2B0><EFBFBD><EFBFBD>ϥΡA<CEA1><41><EFBFBD><EFBFBD><EFBFBD>`<60><><EFBFBD><EFBFBD><EFBFBD>Ӷ}<7D>ҡA<D2A1>קK Log <20>q<EFBFBD>Ӥj<D3A4>A<EFBFBD>Ϧӷ|<7C>y<EFBFBD><79><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD>D<EFBFBD>C (<28>w<EFBFBD>]<5D><><EFBFBD>|<7C><><EFBFBD>X)
|
|||
|
|
|||
|
//Information 2 LogInformation() Logs messages for the flow of the application.
|
|||
|
// <20>`<60><><EFBFBD><EFBFBD> Log <20><><EFBFBD><EFBFBD><EFBFBD>A<EFBFBD>D<EFBFBD>n<EFBFBD>O<EFBFBD><4F><EFBFBD><EFBFBD><EFBFBD>{<7B>չB<D5B9>檺<EFBFBD>y<EFBFBD>{<7B>C
|
|||
|
|
|||
|
//Warning 3 LogWarning() Logs messages for abnormal or unexpected events in the application flow.
|
|||
|
// <20><><EFBFBD><EFBFBD><EFBFBD>i<EFBFBD>w<EFBFBD><77><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>~<7E>Ϊ̮įण<C4AF>Ϊ<EFBFBD><CEAA>ƥ<EFBFBD><C6A5>F<EFBFBD><46><EFBFBD>藍<EFBFBD>|<7C><><EFBFBD>A<EFBFBD><41><EFBFBD><EFBFBD><EFBFBD>F<EFBFBD>|<7C><><EFBFBD>n<EFBFBD><6E><EFBFBD><EFBFBD><EFBFBD>D<EFBFBD>C
|
|||
|
|
|||
|
//Error 4 LogError() Logs error messages.
|
|||
|
// <20><><EFBFBD><EFBFBD><EFBFBD>D<EFBFBD>w<EFBFBD><77><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>~<7E>A<EFBFBD><41><EFBFBD>ӵo<D3B5>ͦ<EFBFBD><CDA6>o<EFBFBD>o<EFBFBD>͡A<CDA1><41><EFBFBD>ӭn<D3AD>קK<D7A7><4B><EFBFBD>Ƶo<C6B5>ͪ<EFBFBD><CDAA><EFBFBD><EFBFBD>~<7E>ƥ<EFBFBD><C6A5>C
|
|||
|
|
|||
|
//Critical 5 LogCritical() Logs failures messages that require immediate attention.
|
|||
|
// <20>u<EFBFBD>n<EFBFBD>o<EFBFBD>ʹN<CDB4>dzƨ<C7B3><C6A8>W<EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD>~<7E>ƥ<EFBFBD><C6A5>A<EFBFBD>Ҧp<D2A6>|<7C>ɭP<C9AD><50><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҡA<D2A1>t<EFBFBD>αY<CEB1>쪺<EFBFBD>ƥ<EFBFBD><C6A5>C
|
|||
|
public static void Main(string[] args)
|
|||
|
{
|
|||
|
// NLog: setup the logger first to catch all errors
|
|||
|
var logger = NLog.Web.NLogBuilder.ConfigureNLog("nlog.config").GetCurrentClassLogger();
|
|||
|
try
|
|||
|
{
|
|||
|
logger.Debug("init main");
|
|||
|
BuildWebHost(args).Build().Run();
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
//NLog: catch setup errors
|
|||
|
logger.Error(ex, "Stopped program because of exception");
|
|||
|
throw;
|
|||
|
}
|
|||
|
finally
|
|||
|
{
|
|||
|
// Ensure to flush and stop internal timers/threads before application-exit (Avoid segmentation fault on Linux)
|
|||
|
NLog.LogManager.Shutdown();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public static IWebHostBuilder BuildWebHost(string[] args) =>
|
|||
|
WebHost.CreateDefaultBuilder(args)
|
|||
|
.UseStartup<Startup>()
|
|||
|
.ConfigureLogging(logging =>
|
|||
|
{
|
|||
|
logging.ClearProviders();
|
|||
|
logging.SetMinimumLevel(LogLevel.Trace);
|
|||
|
})
|
|||
|
.UseNLog(); // NLog: setup NLog for Dependency injection
|
|||
|
}
|
|||
|
}
|