-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add logging * Introduce controller, rather than anonymous handler; configure logging * Add `netcoreapp2.1` sample; Rename `examples` directory to `samples` and adjust namespaces * Fix dependency - for `netcoreapp2.1`, don't depend on `M.E.O.DataAnnotations` (-> apps running on 2.1 won't get options validation) * Update GitHub's `ci.yml` after sample dir renaming * Fix sample route * Update samples; Post-merge fixes
- Loading branch information
Showing
17 changed files
with
248 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 0 additions & 11 deletions
11
...spNetCore.Correlator.Example.NetCore3x/W4k.AspNetCore.Correlator.Example.NetCore3x.csproj
This file was deleted.
Oops, something went wrong.
35 changes: 35 additions & 0 deletions
35
samples/W4k.AspNetCore.Correlator.Example.NetCore2.1/Controllers/HelloController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.Extensions.Logging; | ||
using W4k.AspNetCore.Correlator.Context; | ||
|
||
namespace W4k.AspNetCore.Correlator.Example.NetCore21.Controllers | ||
{ | ||
[Route("api/v1/[controller]")] | ||
[ApiController] | ||
public class HelloController : ControllerBase | ||
{ | ||
private readonly ICorrelationContextAccessor _contextAccessor; | ||
private readonly ILogger<HelloController> _logger; | ||
|
||
public HelloController(ICorrelationContextAccessor contextAccessor, ILogger<HelloController> logger) | ||
{ | ||
_contextAccessor = contextAccessor; | ||
_logger = logger; | ||
} | ||
|
||
[HttpGet] | ||
public ActionResult Hello() | ||
{ | ||
_logger.LogInformation("Entering hello"); | ||
|
||
var correlationId = _contextAccessor.CorrelationContext.CorrelationId; | ||
var result = correlationId.IsEmpty | ||
? "<correlation missing>" | ||
: correlationId; | ||
|
||
_logger.LogInformation("Request almost finished, correlation: {correlationId}", correlationId); | ||
|
||
return Ok(result); | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
samples/W4k.AspNetCore.Correlator.Example.NetCore2.1/Program.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using Microsoft.AspNetCore; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace W4k.AspNetCore.Correlator.Example.NetCore21 | ||
{ | ||
public class Program | ||
{ | ||
public static void Main(string[] args) | ||
{ | ||
CreateWebHostBuilder(args).Build().Run(); | ||
} | ||
|
||
public static IWebHostBuilder CreateWebHostBuilder(string[] args) => | ||
WebHost.CreateDefaultBuilder(args) | ||
.ConfigureLogging(logging => | ||
{ | ||
logging.AddConsole(options => | ||
{ | ||
options.DisableColors = true; | ||
options.IncludeScopes = true; | ||
}); | ||
}) | ||
.UseStartup<Startup>(); | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
samples/W4k.AspNetCore.Correlator.Example.NetCore2.1/Startup.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using W4k.AspNetCore.Correlator.Extensions; | ||
using W4k.AspNetCore.Correlator.Extensions.DependencyInjection; | ||
using W4k.AspNetCore.Correlator.Options; | ||
|
||
namespace W4k.AspNetCore.Correlator.Example.NetCore21 | ||
{ | ||
public class Startup | ||
{ | ||
public Startup(IConfiguration configuration) | ||
{ | ||
Configuration = configuration; | ||
} | ||
|
||
public IConfiguration Configuration { get; } | ||
|
||
// This method gets called by the runtime. Use this method to add services to the container. | ||
public void ConfigureServices(IServiceCollection services) | ||
{ | ||
services.AddDefaultCorrelator(options => | ||
{ | ||
options.Forward = PropagationSettings.PropagateAs("X-Correlation-Id"); | ||
options.Emit = PropagationSettings.PropagateAs("X-Correlation-Id"); | ||
options.LoggingScope = LoggingScopeSettings.IncludeLoggingScope("Correlation"); | ||
}); | ||
|
||
services | ||
.AddHttpClient("DummyClient") | ||
.WithCorrelation(); | ||
|
||
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); | ||
} | ||
|
||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. | ||
public void Configure(IApplicationBuilder app, IHostingEnvironment env) | ||
{ | ||
app.UseCorrelator(); | ||
|
||
if (env.IsDevelopment()) | ||
{ | ||
app.UseDeveloperExceptionPage(); | ||
} | ||
|
||
app.UseMvc(); | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...NetCore.Correlator.Example.NetCore2.1/W4k.AspNetCore.Correlator.Example.NetCore2.1.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp2.1</TargetFramework> | ||
<RootNamespace>W4k.AspNetCore.Correlator.Example.NetCore21</RootNamespace> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.AspNetCore.App" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\W4k.AspNetCore.Correlator\W4k.AspNetCore.Correlator.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
File renamed without changes.
9 changes: 9 additions & 0 deletions
9
samples/W4k.AspNetCore.Correlator.Example.NetCore2.1/appsettings.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Warning", | ||
"W4k.AspNetCore.Correlator": "Debug" | ||
} | ||
}, | ||
"AllowedHosts": "*" | ||
} |
35 changes: 35 additions & 0 deletions
35
samples/W4k.AspNetCore.Correlator.Example.NetCore3.1/Controllers/HelloController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.Extensions.Logging; | ||
using W4k.AspNetCore.Correlator.Context; | ||
|
||
namespace W4k.AspNetCore.Correlator.Example.NetCore31.Controllers | ||
{ | ||
[Route("api/v1/[controller]")] | ||
[ApiController] | ||
public class HelloController : ControllerBase | ||
{ | ||
private readonly ICorrelationContextAccessor _contextAccessor; | ||
private readonly ILogger<HelloController> _logger; | ||
|
||
public HelloController(ICorrelationContextAccessor contextAccessor, ILogger<HelloController> logger) | ||
{ | ||
_contextAccessor = contextAccessor; | ||
_logger = logger; | ||
} | ||
|
||
[HttpGet] | ||
public ActionResult Hello() | ||
{ | ||
_logger.LogInformation("Entering hello"); | ||
|
||
var correlationId = _contextAccessor.CorrelationContext.CorrelationId; | ||
var result = correlationId.IsEmpty | ||
? "<correlation missing>" | ||
: correlationId; | ||
|
||
_logger.LogInformation("Request almost finished, correlation: {correlationId}", correlationId); | ||
|
||
return Ok(result); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
...NetCore.Correlator.Example.NetCore3.1/W4k.AspNetCore.Correlator.Example.NetCore3.1.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp3.1</TargetFramework> | ||
<RootNamespace>W4k.AspNetCore.Correlator.Example.NetCore31</RootNamespace> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\W4k.AspNetCore.Correlator\W4k.AspNetCore.Correlator.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
9 changes: 9 additions & 0 deletions
9
samples/W4k.AspNetCore.Correlator.Example.NetCore3.1/appsettings.Development.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Debug", | ||
"System": "Information", | ||
"Microsoft": "Information" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.