Skip to content

Commit

Permalink
fix aspnet hosting and logging
Browse files Browse the repository at this point in the history
  • Loading branch information
masnider committed Sep 24, 2020
1 parent bb97339 commit 6a7d252
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 53 deletions.
15 changes: 8 additions & 7 deletions src/GettingStartedApplication/StatefulBackendService/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,16 @@ public void ConfigureServices(IServiceCollection services)
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, IServiceCollection factory)
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
factory.AddLogging(options =>
if (env.IsDevelopment())
{
options.AddConfiguration(this.Configuration.GetSection("Logging"));
options.AddConsole();
options.AddDebug();
});
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
}

app.UseMvc();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace StatefulBackendService
using System.IO;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.ServiceFabric.Data;
using Microsoft.ServiceFabric.Services.Communication.AspNetCore;
using Microsoft.ServiceFabric.Services.Communication.Runtime;
Expand Down Expand Up @@ -43,6 +44,12 @@ protected override IEnumerable<ServiceReplicaListener> CreateServiceReplicaListe
return new WebHostBuilder()
.UseKestrel()
.ConfigureLogging(logging =>
{
logging.ClearProviders();
logging.AddConsole();
logging.AddDebug();
})
.ConfigureServices(
services => services
.AddSingleton<IReliableStateManager>(this.StateManager)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Diagnostics" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="3.1.8" />
Expand Down
14 changes: 0 additions & 14 deletions src/GettingStartedApplication/StatefulBackendService/web.config

This file was deleted.

18 changes: 4 additions & 14 deletions src/GettingStartedApplication/WebService/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ namespace WebService
{
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Internal;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Console;


public class Startup
{
Expand All @@ -31,34 +32,23 @@ public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
services.AddMvc();

}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, IServiceCollection factory)
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
factory.AddLogging(options =>
{
options.AddConfiguration(this.Configuration.GetSection("Logging"));
options.AddConsole();
options.AddDebug();
});

//loggerFactory.AddConsole(this.Configuration.GetSection("Logging"));
//loggerFactory.AddDebug();

if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseBrowserLink();
}
else
{
app.UseExceptionHandler("/Home/Error");
}

app.UseStaticFiles();

app.UseMvc(
routes =>
{
Expand Down
13 changes: 10 additions & 3 deletions src/GettingStartedApplication/WebService/WebService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace WebService
using System.Net.Http;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.ServiceFabric.Services.Communication.AspNetCore;
using Microsoft.ServiceFabric.Services.Communication.Runtime;
using Microsoft.ServiceFabric.Services.Runtime;
Expand All @@ -35,15 +36,21 @@ protected override IEnumerable<ServiceInstanceListener> CreateServiceInstanceLis
{
new ServiceInstanceListener(
serviceContext =>
new WebListenerCommunicationListener(
new HttpSysCommunicationListener(
serviceContext,
"ServiceEndpoint",
(url, listener) =>
{
ServiceEventSource.Current.ServiceMessage(serviceContext, $"Starting WebListener on {url}");
ServiceEventSource.Current.ServiceMessage(serviceContext, $"Starting HttpSysListener on {url}");
return new WebHostBuilder()
.UseWebListener()
.UseHttpSys()
.ConfigureLogging(logging =>
{
logging.ClearProviders();
logging.AddConsole();
logging.AddDebug();
})
.ConfigureServices(
services => services
.AddSingleton<ConfigSettings>(new ConfigSettings(serviceContext))
Expand Down
2 changes: 1 addition & 1 deletion src/GettingStartedApplication/WebService/WebService.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="3.1.8" />
<PackageReference Include="Microsoft.ServiceFabric" Version="7.1.458" />
<PackageReference Include="Microsoft.ServiceFabric.Actors" Version="4.1.458" />
<PackageReference Include="Microsoft.ServiceFabric.AspNetCore.WebListener" Version="4.1.458" />
<PackageReference Include="Microsoft.ServiceFabric.AspNetCore.HttpSys" Version="4.1.458" />
<PackageReference Include="Microsoft.ServiceFabric.Data" Version="4.1.458" />
<PackageReference Include="Microsoft.ServiceFabric.Services" Version="4.1.458" />
<PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="2.2.0" />
Expand Down
14 changes: 0 additions & 14 deletions src/GettingStartedApplication/WebService/web.config

This file was deleted.

0 comments on commit 6a7d252

Please sign in to comment.