mirror of
https://github.com/sphildreth/roadie
synced 2024-11-14 00:17:12 +00:00
75 lines
No EOL
3.2 KiB
C#
75 lines
No EOL
3.2 KiB
C#
using Microsoft.AspNetCore;
|
|
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Serilog;
|
|
using System;
|
|
using System.Diagnostics;
|
|
using System.IO;
|
|
|
|
namespace Roadie.Api
|
|
{
|
|
public class Program
|
|
{
|
|
public static void Main(string[] args)
|
|
{
|
|
var dbFilename = Path.Combine("logs", "errors.db");
|
|
Log.Logger = new LoggerConfiguration()
|
|
.ReadFrom.Configuration(Configuration)
|
|
.CreateLogger();
|
|
|
|
try
|
|
{
|
|
Log.Information("Starting web host");
|
|
|
|
Trace.Listeners.Add(new LoggingTraceListener());
|
|
|
|
#if DEBUG
|
|
// Logging Output tests
|
|
Log.Verbose(":: Log Test: Verbose (Trace,None)"); // Microsoft.Extensions.Logging.LogLevel.Trace and Microsoft.Extensions.Logging.LogLevel.None
|
|
Log.Debug(":: Log Test: Debug"); // Microsoft.Extensions.Logging.LogLevel.Debug
|
|
Log.Information(":: Log Test: Information"); // Microsoft.Extensions.Logging.LogLevel.Information
|
|
Log.Warning(":: Log Test: Warning"); // Microsoft.Extensions.Logging.LogLevel.Warning
|
|
Log.Error(new Exception("Log Test Exception"), "Log Test Error Message"); // Microsoft.Extensions.Logging.LogLevel.Error
|
|
Log.Fatal(":: Log Test: Fatal (Critial)"); // Microsoft.Extensions.Logging.LogLevel.Critical
|
|
Trace.WriteLine(":: Log Test: Trace WriteLine()");
|
|
#endif
|
|
Console.WriteLine("");
|
|
Console.WriteLine(@" ____ __ __ ____ __ ____ __ ____ __ ");
|
|
Console.WriteLine(@"( _ \ / \ / _\ ( \( )( __) / _\ ( _ \( ) ");
|
|
Console.WriteLine(@" ) /( O )/ \ ) D ( )( ) _) / \ ) __/ )( ");
|
|
Console.WriteLine(@"(__\_) \__/ \_/\_/(____/(__)(____) \_/\_/(__) (__) ");
|
|
Console.WriteLine("");
|
|
|
|
CreateWebHostBuilder(args).Build().Run();
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Log.Fatal(ex, "Host terminated unexpectedly");
|
|
}
|
|
finally
|
|
{
|
|
Log.CloseAndFlush();
|
|
}
|
|
}
|
|
|
|
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
|
|
WebHost.CreateDefaultBuilder(args)
|
|
.UseStartup<Startup>()
|
|
.UseSerilog();
|
|
|
|
public static IConfiguration Configuration { get; } = new ConfigurationBuilder()
|
|
.SetBasePath(Directory.GetCurrentDirectory())
|
|
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
|
|
.AddJsonFile($"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Production"}.json", optional: true)
|
|
.AddEnvironmentVariables()
|
|
.Build();
|
|
}
|
|
|
|
public class LoggingTraceListener : TraceListener
|
|
{
|
|
public override void Write(string message) => Log.Verbose(message);
|
|
|
|
public override void WriteLine(string message) => Log.Verbose(message);
|
|
}
|
|
} |