Skip to content

Commit

Permalink
Adds Serilog to runtimechecker-sample to show off structured logging
Browse files Browse the repository at this point in the history
  • Loading branch information
johnkors committed Nov 27, 2020
1 parent a07820c commit 7d6e976
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 29 deletions.
17 changes: 16 additions & 1 deletion SampleProjects/VulnerableRunTimeWebApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,15 @@
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Serilog;
using Serilog.Formatting.Compact;
using Serilog.Sinks.SystemConsole.Themes;

namespace VulnerableRunTimeWebApp
{
Expand All @@ -19,6 +25,15 @@ public static void Main(string[] args)

public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>();
.ConfigureServices((app, services) =>
{
services.AddRetireRuntimeHostedService();
})
.Configure(app => app.UseRuntimeVulnerabilityReport())
.UseSerilog((hostingContext, loggerConfiguration) =>
loggerConfiguration
.ReadFrom.Configuration(hostingContext.Configuration)
.WriteTo.Console(new CompactJsonFormatter()));

}
}
22 changes: 0 additions & 22 deletions SampleProjects/VulnerableRunTimeWebApp/Startup.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFrameworks>netcoreapp3.1;net5.0</TargetFrameworks>
<TargetFrameworks>netcoreapp3.1</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.SpaServices" Version="2.1.0" />
<!-- <PackageReference Include="RetireNet.Runtimes.BackgroundServices" Version="0.7.1" />-->
<!-- <PackageReference Include="RetireNet.Runtimes.Middleware" Version="0.7.1" />-->
<PackageReference Include="Serilog.AspNetCore" Version="3.4.0" />

<!-- <PackageReference Include="RetireNet.Runtimes.BackgroundServices" Version="5.0.0" />-->
<!-- <PackageReference Include="RetireNet.Runtimes.Middleware" Version="5.0.0" />-->
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\RetireNet.Runtimes.BackgroundServices\RetireNet.Runtimes.BackgroundServices.csproj" />
<ProjectReference Include="..\..\src\RetireNet.Runtimes.Middleware\RetireNet.Runtimes.Middleware.csproj" />
<ProjectReference Include="..\..\src\RetireNet.Runtimes.BackgroundServices\RetireNet.Runtimes.BackgroundServices.csproj" />
<ProjectReference Include="..\..\src\RetireNet.Runtimes.Middleware\RetireNet.Runtimes.Middleware.csproj" />

</ItemGroup>


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)
var report = await _reportGenerator.GetReport(AppRunTimeDetails.Build());
if (report.IsVulnerable.HasValue && report.IsVulnerable.Value)
{
_logger.LogWarning("Running on vulnerable runtime {appruntime}. Security release {securityrelease}", report.AppRuntimeDetails.AppRuntimeVersion, report.SecurityRelease.RuntimeVersion);
_logger.LogWarning("Running on vulnerable runtime {VulnerableRuntime}. Security release {SecurityPatch}", report.AppRuntimeDetails.AppRuntimeVersion, report.SecurityRelease.RuntimeVersion);

}
await Task.Delay(optionsCheckInterval, stoppingToken);
Expand Down

0 comments on commit 7d6e976

Please sign in to comment.