forked from sanagama/mssql-restapi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
68 lines (63 loc) · 2.11 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using Serilog;
using Serilog.Events;
using MSSqlRestApi.Models;
namespace MSSqlRestApi
{
public class Program
{
public static int Main(string[] args)
{
// Initialize Serilog
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug()
.MinimumLevel.Override("Microsoft", LogEventLevel.Information)
.Enrich.FromLogContext()
.WriteTo.Console()
.CreateLogger();
try
{
Log.Information("*** REST API for SQL Server, Azure SQL Database and Azure SQL Data Warehouse.");
TestSqlServerConnection();
StartWebHost();
return 0;
}
catch (Exception ex)
{
Log.Fatal(ex, "*** Host terminated unexpectedly, examine exception.");
return 1;
}
finally
{
Log.CloseAndFlush();
}
}
private static void TestSqlServerConnection()
{
Log.Information("Testing connection to SQL Server");
var ctx = new ServerContext();
Log.Information("Test connection successful. SQL Server version: {0}", ctx.SmoServer.VersionString);
}
private static void StartWebHost()
{
Log.Information("Starting Web Host");
var host = new WebHostBuilder()
.UseKestrel()
.UseUrls("http://*:5000") // listen on port 5000 on all network interfaces
.UseIISIntegration()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseStartup<Startup>()
.UseSerilog()
.Build();
host.Run();
}
}
}