Skip to content

Commit 6ccd7b6

Browse files
committed
Ass Seq to SignalR.Hub
1 parent 21427eb commit 6ccd7b6

4 files changed

Lines changed: 83 additions & 32 deletions

File tree

src/Services/Ordering/Ordering.SignalrHub/Ordering.SignalrHub.csproj

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,25 @@
1111

1212
<ItemGroup>
1313
<PackageReference Include="AspNetCore.HealthChecks.AzureServiceBus" Version="2.2.0" />
14-
<PackageReference Include="AspNetCore.HealthChecks.UI.Client" Version="2.2.0" />
1514
<PackageReference Include="AspNetCore.HealthChecks.Rabbitmq" Version="2.2.0" />
15+
<PackageReference Include="AspNetCore.HealthChecks.UI.Client" Version="2.2.0" />
1616
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="4.2.1" />
17-
<PackageReference Include="Microsoft.AspNetCore.App" Version="2.2.0" />
17+
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.2.1" />
18+
<PackageReference Include="Microsoft.ApplicationInsights.DependencyCollector" Version="2.6.1" />
19+
<PackageReference Include="Microsoft.ApplicationInsights.Kubernetes" Version="1.0.0-beta8" />
20+
<PackageReference Include="Microsoft.ApplicationInsights.ServiceFabric" Version="2.1.1-beta1" />
21+
<PackageReference Include="Microsoft.AspNetCore.App" />
1822
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.HealthChecks" Version="2.2.0" />
1923
<PackageReference Include="Microsoft.AspNetCore.HealthChecks" Version="1.0.0" />
2024
<PackageReference Include="Microsoft.AspNetCore.SignalR" Version="1.1.0" />
2125
<PackageReference Include="Microsoft.AspNetCore.SignalR.Core" Version="1.1.0" />
2226
<PackageReference Include="Microsoft.AspNetCore.SignalR.Redis" Version="1.1.0" />
23-
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.2.1" />
24-
<PackageReference Include="Microsoft.ApplicationInsights.DependencyCollector" Version="2.6.1" />
25-
<PackageReference Include="Microsoft.ApplicationInsights.Kubernetes" Version="1.0.0-beta8" />
26-
<PackageReference Include="Microsoft.ApplicationInsights.ServiceFabric" Version="2.1.1-beta1" />
27-
<PackageReference Include="Microsoft.Extensions.Logging.AzureAppServices" Version="2.2.0-preview3-35497" />
28-
<PackageReference Include="Microsoft.Extensions.Logging.AzureAppServices" Version="2.1.0" />
27+
<PackageReference Include="Microsoft.Extensions.Logging.AzureAppServices" Version="2.2.0" />
2928
<PackageReference Include="Serilog.AspNetCore" Version="2.1.1" />
29+
<PackageReference Include="Serilog.Enrichers.Environment" Version="2.1.2" />
30+
<PackageReference Include="Serilog.Settings.Configuration" Version="3.0.1" />
3031
<PackageReference Include="Serilog.Sinks.Console" Version="3.1.1" />
32+
<PackageReference Include="Serilog.Sinks.Seq" Version="4.0.0" />
3133
</ItemGroup>
3234

3335
<ItemGroup>

src/Services/Ordering/Ordering.SignalrHub/Program.cs

Lines changed: 56 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,67 @@ namespace Ordering.SignalrHub
1313
{
1414
public class Program
1515
{
16-
public static void Main(string[] args)
16+
public static readonly string AppName = typeof(Program).Namespace;
17+
public static readonly string AppShortName = AppName.Substring(AppName.LastIndexOf('.', AppName.LastIndexOf('.') - 1) + 1);
18+
19+
public static int Main(string[] args)
1720
{
18-
BuildWebHost(args).Run();
21+
var configuration = GetConfiguration();
22+
23+
Log.Logger = CreateSerilogLogger(configuration);
24+
25+
try
26+
{
27+
Log.Information("Configuring web host ({Application})...", AppName);
28+
var host = BuildWebHost(configuration, args);
29+
30+
Log.Information("Starting web host ({Application})...", AppName);
31+
host.Run();
32+
33+
return 0;
34+
}
35+
catch (Exception ex)
36+
{
37+
Log.Fatal(ex, "Program terminated unexpectedly ({Application})!", AppName);
38+
return 1;
39+
}
40+
finally
41+
{
42+
Log.CloseAndFlush();
43+
}
1944
}
2045

21-
public static IWebHost BuildWebHost(string[] args) =>
46+
private static IWebHost BuildWebHost(IConfiguration configuration, string[] args) =>
2247
WebHost.CreateDefaultBuilder(args)
48+
.CaptureStartupErrors(false)
2349
.UseStartup<Startup>()
24-
.UseSerilog((builderContext, config) =>
25-
{
26-
config
27-
.MinimumLevel.Information()
28-
.Enrich.FromLogContext()
29-
.WriteTo.Console();
30-
})
50+
.UseConfiguration(configuration)
51+
.UseSerilog()
3152
.Build();
53+
54+
private static Serilog.ILogger CreateSerilogLogger(IConfiguration configuration)
55+
{
56+
var seqServerUrl = configuration["Serilog:SeqServerUrl"];
57+
58+
return new LoggerConfiguration()
59+
.MinimumLevel.Verbose()
60+
.Enrich.WithProperty("Application", AppName)
61+
.Enrich.FromLogContext()
62+
.WriteTo.Console()
63+
.WriteTo.Seq(string.IsNullOrWhiteSpace(seqServerUrl) ? "http://seq" : seqServerUrl)
64+
.ReadFrom.Configuration(configuration)
65+
.CreateLogger();
66+
}
67+
68+
private static IConfiguration GetConfiguration()
69+
{
70+
var builder = new ConfigurationBuilder()
71+
.SetBasePath(Directory.GetCurrentDirectory())
72+
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
73+
.AddEnvironmentVariables();
74+
75+
return builder.Build();
76+
}
77+
3278
}
3379
}

src/Services/Ordering/Ordering.SignalrHub/Startup.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ public Startup(IConfiguration configuration)
3030
Configuration = configuration;
3131
}
3232

33+
public IConfiguration Configuration { get; }
34+
3335
// This method gets called by the runtime. Use this method to add services to the container.
3436
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
3537
public IServiceProvider ConfigureServices(IServiceCollection services)
@@ -115,15 +117,13 @@ public IServiceProvider ConfigureServices(IServiceCollection services)
115117
return new AutofacServiceProvider(container.Build());
116118
}
117119

118-
public IConfiguration Configuration { get; }
119-
120120
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
121121
public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
122122
{
123-
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
124-
loggerFactory.AddDebug();
125-
loggerFactory.AddAzureWebAppDiagnostics();
126-
loggerFactory.AddApplicationInsights(app.ApplicationServices, LogLevel.Trace);
123+
//loggerFactory.AddConsole(Configuration.GetSection("Logging"));
124+
//loggerFactory.AddDebug();
125+
//loggerFactory.AddAzureWebAppDiagnostics();
126+
//loggerFactory.AddApplicationInsights(app.ApplicationServices, LogLevel.Trace);
127127

128128
var pathBase = Configuration["PATH_BASE"];
129129
if (!string.IsNullOrEmpty(pathBase))
@@ -159,13 +159,13 @@ public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
159159
private void ConfigureEventBus(IApplicationBuilder app)
160160
{
161161
var eventBus = app.ApplicationServices.GetRequiredService<IEventBus>();
162-
162+
163163
eventBus.Subscribe<OrderStatusChangedToAwaitingValidationIntegrationEvent, OrderStatusChangedToAwaitingValidationIntegrationEventHandler>();
164164
eventBus.Subscribe<OrderStatusChangedToPaidIntegrationEvent, OrderStatusChangedToPaidIntegrationEventHandler>();
165165
eventBus.Subscribe<OrderStatusChangedToStockConfirmedIntegrationEvent, OrderStatusChangedToStockConfirmedIntegrationEventHandler>();
166166
eventBus.Subscribe<OrderStatusChangedToShippedIntegrationEvent, OrderStatusChangedToShippedIntegrationEventHandler>();
167167
eventBus.Subscribe<OrderStatusChangedToCancelledIntegrationEvent, OrderStatusChangedToCancelledIntegrationEventHandler>();
168-
eventBus.Subscribe<OrderStatusChangedToSubmittedIntegrationEvent, OrderStatusChangedToSubmittedIntegrationEventHandler>();
168+
eventBus.Subscribe<OrderStatusChangedToSubmittedIntegrationEvent, OrderStatusChangedToSubmittedIntegrationEventHandler>();
169169
}
170170

171171
private void ConfigureAuthService(IServiceCollection services)

src/Services/Ordering/Ordering.SignalrHub/appsettings.json

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
{
22
"IdentityUrl": "http://localhost:5105",
3-
"Logging": {
4-
"IncludeScopes": false,
5-
"LogLevel": {
6-
"Default": "Trace",
7-
"System": "Information",
8-
"Microsoft": "Information"
3+
"Serilog": {
4+
"SeqServerUrl": null,
5+
"MinimumLevel": {
6+
"Default": "Information",
7+
"Override": {
8+
"Microsoft": "Warning",
9+
"Microsoft.eShopOnContainers": "Information",
10+
"System": "Warning"
11+
}
912
}
1013
},
1114
"AzureServiceBusEnabled": false,

0 commit comments

Comments
 (0)