-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.vb
45 lines (38 loc) · 1.93 KB
/
Program.vb
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
Imports System.IO
Imports Microsoft.EntityFrameworkCore
Imports Microsoft.Extensions.Configuration
Imports Microsoft.Extensions.DependencyInjection
Imports Microsoft.Extensions.Hosting
Imports Serilog
Module Program
Sub Main(args As String())
Dim builder As IConfigurationBuilder = New ConfigurationBuilder()
builder.SetBasePath(Directory.GetCurrentDirectory).
AddJsonFile("appsettings.json", optional:=False, reloadOnChange:=True).
AddJsonFile($"appsetting.{If(Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT"), "Production")}.json", [optional]:=True).
AddEnvironmentVariables()
Dim LoggerConfiguration = New LoggerConfiguration().ReadFrom.
Configuration(builder.Build()).
Enrich.FromLogContext()
Dim AspNetHost = Host.CreateDefaultBuilder().
ConfigureServices(Sub(X, Y)
ConfigureDI(X, Y)
End Sub).
UseSerilog().
Build()
LoggerConfiguration.WriteTo.File("test.txt").WriteTo.Console()
Log.Logger = LoggerConfiguration.CreateLogger()
Log.Logger.Information("start")
Dim Test As IWriteToPostgres = AspNetHost.Services.GetService(Of WriteToPostgres)
Test.Write(1000)
End Sub
Sub ConfigureDI(Context As HostBuilderContext, ByRef Services As IServiceCollection)
Services.AddScoped(Of WriteToPostgres)
Services.AddScoped(Of WeatherForecast)
Services.AddDbContext(Of ApplicationDbContext)(Sub(options)
options.UseNpgsql(Context.Configuration.GetConnectionString("Default"))
options.EnableSensitiveDataLogging(True)
options.EnableDetailedErrors()
End Sub, ServiceLifetime.Transient)
End Sub
End Module