Skip to content

Commit

Permalink
Merge pull request #188 from nblumhardt/sample-net60-only
Browse files Browse the repository at this point in the history
Update sample to target .NET 6
  • Loading branch information
nblumhardt authored Oct 17, 2022
2 parents 3025dfc + 475cc2c commit 30294f5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 39 deletions.
58 changes: 24 additions & 34 deletions sample/Sample/Program.cs
Original file line number Diff line number Diff line change
@@ -1,46 +1,36 @@
using System;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Serilog;
using Serilog.Core;

namespace Sample
{
public static class Program
{
public static async Task Main()
{
// By sharing between the Seq sink and logger itself,
// Seq API keys can be used to control the level of the whole logging pipeline.
var levelSwitch = new LoggingLevelSwitch();
// By sharing between the Seq sink and logger itself,
// Seq API keys can be used to control the level of the whole logging pipeline.
var levelSwitch = new LoggingLevelSwitch();

try
{
Log.Logger = new LoggerConfiguration()
.MinimumLevel.ControlledBy(levelSwitch)
.WriteTo.Console()
.WriteTo.Seq("http://localhost:5341", controlLevelSwitch: levelSwitch)
.CreateLogger();
try
{
Log.Logger = new LoggerConfiguration()
.MinimumLevel.ControlledBy(levelSwitch)
.WriteTo.Console()
.WriteTo.Seq("http://localhost:5341", controlLevelSwitch: levelSwitch)
.CreateLogger();

Log.Information("Sample starting up");
Log.Information("Sample starting up");

foreach (var i in Enumerable.Range(0, 100))
{
Log.Information("Running loop {Counter}, switch is at {Level}", i, levelSwitch.MinimumLevel);
foreach (var i in Enumerable.Range(0, 100))
{
Log.Information("Running loop {Counter}, switch is at {Level}", i, levelSwitch.MinimumLevel);

Thread.Sleep(1000);
Log.Debug("Loop iteration done");
}
}
catch (Exception ex)
{
Log.Error(ex, "Unhandled exception");
}
finally
{
await Log.CloseAndFlushAsync();
}
}
Thread.Sleep(1000);
Log.Debug("Loop iteration done");
}
}
catch (Exception ex)
{
Log.Error(ex, "Unhandled exception");
}
finally
{
await Log.CloseAndFlushAsync();
}
6 changes: 1 addition & 5 deletions sample/Sample/Sample.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net4.8;net5.0</TargetFrameworks>
<TargetFramework>net6.0</TargetFramework>
<OutputType>Exe</OutputType>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
Expand All @@ -10,10 +10,6 @@
<ItemGroup>
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net4.8' ">
<Reference Include="System.Net.Http" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Serilog.Sinks.Seq\Serilog.Sinks.Seq.csproj" />
Expand Down

0 comments on commit 30294f5

Please sign in to comment.