Skip to content

Commit bbd4479

Browse files
authored
Merge pull request #461 from serilog-mssql/dev
Release 6.2.0
2 parents 1a173c1 + 91de3d5 commit bbd4479

23 files changed

+275
-43
lines changed

.github/workflows/pr-analysis-codeql.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ on:
1010
workflow_dispatch:
1111

1212
jobs:
13-
build-and-analyze:
13+
build-and-codeql:
1414
runs-on: windows-latest
1515
permissions:
1616
actions: read

.github/workflows/pr-analysis-devskim.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ on:
1010
workflow_dispatch:
1111

1212
jobs:
13-
analyze:
13+
devskim:
1414
runs-on: ubuntu-latest
1515
permissions:
1616
actions: read
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: PR Analysis InferSharp
2+
3+
on:
4+
workflow_run:
5+
workflows: [ "PR Validation" ]
6+
types:
7+
- completed
8+
9+
# Allows you to run this workflow manually from the Actions tab
10+
workflow_dispatch:
11+
12+
jobs:
13+
download-and-infersharp:
14+
runs-on: ubuntu-latest
15+
permissions:
16+
actions: read
17+
contents: read
18+
security-events: write
19+
20+
steps:
21+
- name: Download binaries artifact from PR Validation workflow
22+
id: download-artifact
23+
uses: dawidd6/action-download-artifact@v2
24+
with:
25+
workflow: pr-validation.yml
26+
workflow_conclusion: success
27+
name: bin-net6
28+
path: bin-net6
29+
branch: ${{ github.ref }}
30+
check_artifacts: true
31+
search_artifacts: true
32+
33+
- name: Run Infer#
34+
uses: microsoft/[email protected]
35+
id: runinfersharp
36+
with:
37+
binary-path: bin-net6
38+
39+
- name: Upload SARIF output to GitHub Security Center
40+
uses: github/codeql-action/upload-sarif@v2
41+
with:
42+
sarif_file: infer-out/report.sarif

.github/workflows/pr-validation.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,15 @@ jobs:
1515

1616
- name: Run build and tests
1717
run: ./Build.ps1
18+
19+
- name: Upload binaries artifact for InferSharp workflow
20+
uses: actions/upload-artifact@v3
21+
with:
22+
name: bin-net6
23+
path: src\Serilog.Sinks.MSSqlServer\bin\Release\net6.0
24+
25+
- name: Upload testresults artifact with code coverage file
26+
uses: actions/upload-artifact@v3
27+
with:
28+
name: testresults
29+
path: test\Serilog.Sinks.MSSqlServer.Tests\TestResults

Build.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ if ($SkipTests -eq $false) {
5454

5555
echo "build: Testing project in $test"
5656

57-
& dotnet test -c Release
57+
& dotnet test -c Release --collect "XPlat Code Coverage"
5858
if($LASTEXITCODE -ne 0) { exit 3 }
5959

6060
Pop-Location

CHANGES.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# 6.2.0
2+
* Implemented #454: LoggingLevelSwitch support to allows log level manipulation at runtime.
3+
* Fixed issue #458: Error if enrich nullable int columns by null value
4+
* Added CodeQL code scanning
5+
* Generate code coverage file when running tests in Build.ps1
6+
17
# 6.1.0
28
* Fixed issues #207, #435, #419 & #292: Resolve hierarchical property expressions for additional columns
39
* Fixed issue #432: Write full exception info to SelfLog

Directory.Packages.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="6.0.1" />
1717
<PackageVersion Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="6.0.0" />
1818
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="1.1.1" />
19+
<PackageVersion Include="coverlet.collector" Version="3.2.0" />
1920
<PackageVersion Include="FluentAssertions" Version="6.7.0" />
2021
<PackageVersion Include="Dapper.StrongName" Version="2.0.123" />
2122
<PackageVersion Include="Moq" Version="4.18.2" />

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ All properties in the `MSSqlServerSinkOptions` object are discussed in the [MSSq
6060

6161
Table configuration with the optional `ColumnOptions` object is a lengthy subject discussed in the [ColumnOptions Object](#columnoptions-object) topic and other related topics.
6262

63-
Like other sinks, `restrictedToMinimumLevel` controls the `LogEventLevel` messages that are processed by this sink.
63+
Like other sinks, `restrictedToMinimumLevel` controls the `LogEventLevel` messages that are processed by this sink. This parameter is ignored if the property [LevelSwitch](#levelswitch) in the sink options is set.
6464

6565
This is a "periodic batching sink." The sink will queue a certain number of log events before they're actually written to SQL Server as a bulk insert operation. There is also a timeout period so that the batch is always written even if it has not been filled. By default, the batch size is 50 rows and the timeout is 5 seconds. You can change these through by setting the `MSSqlServerSinkOptions.BatchPostingLimit` and `MSSqlServerSinkOptions.BatchPeriod` arguments.
6666

@@ -244,6 +244,7 @@ Basic settings of the sink are configured using the properties in a `MSSqlServer
244244
* `BatchPostingLimit`
245245
* `BatchPeriod`
246246
* `EagerlyEmitFirstEvent`
247+
* `LevelSwitch`
247248

248249
### TableName
249250

@@ -281,6 +282,9 @@ This setting is not used by the audit sink as it writes each event immediately a
281282
A Flag to eagerly write a batch to the database containing the first received event regardless of `BatchPostingLimit` or `BatchPeriod`. It defaults to `true`.
282283
This setting is not used by the audit sink as it writes each event immediately and not in a batched manner.
283284

285+
### LevelSwitch
286+
287+
A switch allowing the pass-through minimum level to be changed at runtime. If this is set, the parameter `restrictedToMinimumLevel` in the [sink configuration method](#sink-configuration) is ignored.
284288

285289
## ColumnOptions Object
286290

sample/CombinedConfigDemo/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public static void Main()
4949
columnOptionsSection: columnOptionsSection)
5050
.CreateLogger();
5151

52-
Log.Information("Hello {Name} from thread {ThreadId}", Environment.GetEnvironmentVariable("USERNAME"), Thread.CurrentThread.ManagedThreadId);
52+
Log.Information("Hello {Name} from thread {ThreadId}", Environment.GetEnvironmentVariable("USERNAME"), Environment.CurrentManagedThreadId);
5353

5454
Log.Warning("No coins remain at position {@Position}", new { Lat = 25, Long = 134 });
5555

sample/CustomLogEventFormatterDemo/Program.cs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Threading;
33
using Serilog;
4+
using Serilog.Core;
45
using Serilog.Sinks.MSSqlServer;
56

67
namespace CustomLogEventFormatterDemo
@@ -16,6 +17,7 @@ public static void Main()
1617
var options = new ColumnOptions();
1718
options.Store.Add(StandardColumn.LogEvent);
1819
var customFormatter = new FlatLogEventFormatter();
20+
var levelSwitch = new LoggingLevelSwitch();
1921

2022
// Legacy interace - do not use this anymore
2123
//Log.Logger = new LoggerConfiguration()
@@ -40,7 +42,8 @@ public static void Main()
4042
{
4143
TableName = _tableName,
4244
SchemaName = _schemaName,
43-
AutoCreateSqlTable = true
45+
AutoCreateSqlTable = true,
46+
LevelSwitch = levelSwitch
4447
},
4548
appConfiguration: null,
4649
restrictedToMinimumLevel: Serilog.Events.LogEventLevel.Verbose,
@@ -54,10 +57,12 @@ public static void Main()
5457
{
5558
Log.Debug("Getting started");
5659

57-
Log.Information("Hello {Name} from thread {ThreadId}", Environment.GetEnvironmentVariable("USERNAME"), Thread.CurrentThread.ManagedThreadId);
60+
Log.Information("Hello {Name} from thread {ThreadId}", Environment.GetEnvironmentVariable("USERNAME"), Environment.CurrentManagedThreadId);
5861

5962
Log.Warning("No coins remain at position {@Position}", new { Lat = 25, Long = 134 });
6063

64+
UseLevelSwitchToModifyLogLevelDuringRuntime(levelSwitch);
65+
6166
Fail();
6267
}
6368
catch (DivideByZeroException e)
@@ -68,6 +73,19 @@ public static void Main()
6873
Log.CloseAndFlush();
6974
}
7075

76+
private static void UseLevelSwitchToModifyLogLevelDuringRuntime(LoggingLevelSwitch levelSwitch)
77+
{
78+
levelSwitch.MinimumLevel = Serilog.Events.LogEventLevel.Error;
79+
80+
Log.Information("This should not be logged");
81+
82+
Log.Error("This should be logged");
83+
84+
levelSwitch.MinimumLevel = Serilog.Events.LogEventLevel.Information;
85+
86+
Log.Information("This should be logged again");
87+
}
88+
7189
private static void Fail()
7290
{
7391
throw new DivideByZeroException();

0 commit comments

Comments
 (0)