Skip to content

Commit e29c3fb

Browse files
authored
Merge pull request #101 from serilog-contrib/dev
version 9
2 parents 1f882e4 + d296f27 commit e29c3fb

21 files changed

+479
-196
lines changed

.github/workflows/build.yml

Lines changed: 41 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
name: Build
22

33
env:
4-
BUILD_VERSION: "8.5.${{github.run_number}}${{github.ref != 'refs/heads/master' && '-beta' || ''}}"
5-
BUILD_INFORMATION: "8.5.${{github.run_number}}${{github.ref != 'refs/heads/master' && '-beta' || ''}}+Branch.${{github.ref_name}}.Sha.${{github.sha}}"
4+
DOTNET_NOLOGO: true
5+
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
6+
BUILD_PATH: '${{github.workspace}}/artifacts'
67

78
on:
89
push:
910
branches:
1011
- master
1112
- dev
13+
tags:
14+
- 'v*'
1215
pull_request:
1316
branches:
1417
- master
@@ -32,48 +35,61 @@ jobs:
3235
steps:
3336
- name: Checkout
3437
uses: actions/checkout@v3
38+
with:
39+
fetch-depth: 0
3540

3641
- name: Setup .NET
3742
uses: actions/setup-dotnet@v3
3843
with:
3944
dotnet-version: |
40-
3.1.x
41-
6.0.x
45+
3.1.x
46+
6.0.x
47+
7.0.x
4248
4349
- name: Restore Dependencies
4450
run: dotnet restore
4551

4652
- name: Build Project
47-
run: 'dotnet build --no-restore --configuration Release -p:Version="${{env.BUILD_VERSION}}" -p:InformationalVersion="${{env.BUILD_INFORMATION}}"'
53+
run: 'dotnet build --no-restore --configuration Release'
4854

4955
- name: Test Project
5056
run: 'dotnet test --no-build --no-restore --configuration Release'
5157

5258
- name: Create Packages
5359
if: success() && github.event_name != 'pull_request'
54-
run: 'dotnet pack --configuration Release --include-symbols --include-source --no-build --no-restore --output "${{github.workspace}}/artifacts" -p:PackageVersion="${{env.BUILD_VERSION}}"'
60+
run: 'dotnet pack --configuration Release --include-symbols --include-source --no-build --no-restore --output "${{env.BUILD_PATH}}"'
5561

56-
- name: Upload Artifacts
62+
- name: Upload Packages
5763
if: success() && github.event_name != 'pull_request'
5864
uses: actions/upload-artifact@v3
5965
with:
60-
name: artifacts
61-
path: '${{github.workspace}}/artifacts'
66+
name: packages
67+
path: '${{env.BUILD_PATH}}'
68+
69+
deploy:
70+
runs-on: ubuntu-latest
71+
needs: build
72+
if: success() && github.event_name != 'pull_request' && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/dev' || startsWith(github.ref, 'refs/tags/v'))
73+
74+
steps:
75+
- name: Download Artifact
76+
uses: actions/download-artifact@v3
77+
with:
78+
name: packages
79+
80+
- name: Publish Packages GitHub
81+
run: |
82+
for package in $(find -name "*.nupkg"); do
83+
echo "${0##*/}": Pushing $package...
84+
dotnet nuget push $package --source https://nuget.pkg.github.com/serilog-contrib/index.json --api-key ${{ secrets.GITHUB_TOKEN }} --skip-duplicate
85+
done
86+
87+
- name: Publish Packages Nuget
88+
if: startsWith(github.ref, 'refs/tags/v')
89+
run: |
90+
for package in $(find -name "*.nupkg"); do
91+
echo "${0##*/}": Pushing $package...
92+
dotnet nuget push $package --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.NUGET_API_KEY }} --skip-duplicate
93+
done
6294
63-
- name: Publish GitHub Packages
64-
if: success() && github.event_name != 'pull_request'
65-
run: dotnet nuget push ./artifacts/*.nupkg --source https://nuget.pkg.github.com/serilog-contrib/index.json --api-key ${GITHUB_TOKEN} --skip-duplicate
66-
env:
67-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6895
69-
- name: Publish NuGet Packages
70-
if: success() && github.event_name != 'pull_request'
71-
run: dotnet nuget push ./artifacts/*.nupkg --source https://api.nuget.org/v3/index.json --api-key ${NUGET_API_KEY} --skip-duplicate
72-
env:
73-
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
74-
75-
- name: Create Release
76-
if: success() && github.event_name != 'pull_request' && startsWith(github.ref, 'refs/heads/master')
77-
run: 'gh release create "${{env.BUILD_VERSION}}" ./artifacts/*.nupkg --title "v${{env.BUILD_VERSION}}"'
78-
env:
79-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

CHANGES.md

Lines changed: 0 additions & 27 deletions
This file was deleted.

README.md

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,26 @@ var log = new LoggerConfiguration()
99
.CreateLogger();
1010
```
1111

12+
## Configuration
13+
14+
| Configuration | Description | Default |
15+
|-------------------------------|-------------------------------------------------------------------------------------|---------------------------|
16+
| connectionString | The Cloud Storage Account connection string | |
17+
| sharedAccessSignature | The storage account/table SAS key | |
18+
| accountName | The storage account name | |
19+
| restrictedToMinimumLevel | The minimum log event level required in order to write an event to the sink. | Verbose |
20+
| formatProvider | Culture-specific formatting information | |
21+
| storageTableName | Table name that log entries will be written to | LogEvent |
22+
| writeInBatches | Use a periodic batching sink, as opposed to a synchronous one-at-a-time sink | true |
23+
| batchPostingLimit | The maximum number of events to post in a single batch | 100 |
24+
| period | The time to wait between checking for event batches | 0:0:2 |
25+
| keyGenerator | The key generator used to create the PartitionKey and the RowKey for each log entry | DefaultKeyGenerator |
26+
| propertyColumns | Specific log event properties to be written as table columns | |
27+
| bypassTableCreationValidation | Bypass the exception in case the table creation fails | false |
28+
| documentFactory | Provider to create table document from LogEvent | DefaultDocumentFactory |
29+
| tableClientFactory | Provider to create table client | DefaultTableClientFactory |
30+
| partitionKeyRounding | Partition key rounding time span | 0:5:0 |
31+
1232
### JSON configuration
1333

1434
It is possible to configure the sink using [Serilog.Settings.Configuration](https://github.com/serilog/serilog-settings-configuration) by specifying the table name and connection string in `appsettings.json`:
@@ -51,9 +71,6 @@ In your application's `App.config` or `Web.config` file, specify the file sink a
5171
</configuration>
5272
```
5373

54-
### Async approach
55-
It is possible to configure the collector using [Serilog.Sinks.Async](https://github.com/serilog/serilog-sinks-async) to have an async approach.
56-
5774
### Example Configuration for ASP.NET
5875

5976
```c#
@@ -140,3 +157,41 @@ public static class Program
140157
}
141158
}
142159
```
160+
161+
### Change Log
162+
163+
9.0.0
164+
* Breaking: Due to issue with creating provides from configuration
165+
* `IDocumentFactory.Create` add AzureTableStorageSinkOptions and IKeyGenerator arguments
166+
* `IKeyGenerator.GeneratePartitionKey` add AzureTableStorageSinkOptions argument
167+
* `IKeyGenerator.GenerateRowKey` add AzureTableStorageSinkOptions argument
168+
* Fix: DefaultDocumentFactory and DefaultKeyGenerator needed paramaterless contructor for use in configuration files
169+
* Add: ITableClientFactory to control TableClient creation
170+
171+
8.5.0
172+
* Add option for partition key rounding
173+
* Move IKeyGenertor from options
174+
* Add DateTime extension methods for partition key and row key
175+
* Add sample web project
176+
177+
8.0.0
178+
* Breaking: major refactor to simplify code base
179+
* Removed: AzureTableStorageWithProperties extension removed, use equivalent AzureTableStorage
180+
* Removed: ICloudTableProvider provider removed
181+
* Added: IDocumentFactory to allow control over table document
182+
* Change: PartitionKey and RowKey changed to new implementation
183+
184+
7.0.0
185+
* Update dependencies: repace Microsoft.Azure.Cosmos.Table with Azure.Data.Tables
186+
187+
6.0.0
188+
* Updated dependencies: replace deprecated package WindowsAzure.Storage with Microsoft.Azure.Cosmos.Table 1.0.8
189+
* Updated dependencies: Serilog 2.10.0
190+
191+
5.0.0
192+
* Migrated to new CSPROJ project system
193+
* Updated dependencies: WindowsAzure.Storage 8.6.0, Serilog 2.6.0, Serilog.Sinks.PeriodicBatching 2.1.1
194+
* Fix #36 - Allow using SAS URI for logging.
195+
196+
1.5
197+
* Moved from serilog/serilog
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using Serilog.Events;
2+
using Serilog.Sinks.AzureTableStorage;
3+
using Serilog.Sinks.AzureTableStorage.Extensions;
4+
5+
namespace SampleConsoleApplication;
6+
7+
public class CustomKeyGenerator : IKeyGenerator
8+
{
9+
public virtual string GeneratePartitionKey(LogEvent logEvent, AzureTableStorageSinkOptions options)
10+
{
11+
var utcEventTime = logEvent.Timestamp.UtcDateTime;
12+
return utcEventTime.GeneratePartitionKey();
13+
}
14+
15+
public virtual string GenerateRowKey(LogEvent logEvent, AzureTableStorageSinkOptions options)
16+
{
17+
var utcEventTime = logEvent.Timestamp.UtcDateTime;
18+
return utcEventTime.GenerateRowKey();
19+
}
20+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using Microsoft.Extensions.Hosting;
2+
using Microsoft.Extensions.Logging;
3+
4+
namespace SampleConsoleApplication;
5+
6+
public class PrintTimeService : BackgroundService
7+
{
8+
private readonly ILogger<PrintTimeService> _logger;
9+
10+
public PrintTimeService(ILogger<PrintTimeService> logger)
11+
{
12+
_logger = logger;
13+
}
14+
15+
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
16+
{
17+
while (!stoppingToken.IsCancellationRequested)
18+
{
19+
_logger.LogInformation("The current time is: {CurrentTime}", DateTimeOffset.UtcNow);
20+
await Task.Delay(TimeSpan.FromSeconds(5), stoppingToken);
21+
}
22+
}
23+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using Microsoft.Extensions.DependencyInjection;
2+
using Microsoft.Extensions.Hosting;
3+
4+
using Serilog;
5+
using Serilog.Events;
6+
7+
namespace SampleConsoleApplication;
8+
9+
internal class Program
10+
{
11+
private const string OutputTemplate = "{Timestamp:HH:mm:ss.fff} [{Level:u1}] {Message:lj}{NewLine}{Exception}";
12+
13+
public static async Task<int> Main(string[] args)
14+
{
15+
Log.Logger = new LoggerConfiguration()
16+
.MinimumLevel.Verbose()
17+
.MinimumLevel.Override("Microsoft", LogEventLevel.Information)
18+
.Enrich.FromLogContext()
19+
.WriteTo.Console(outputTemplate: OutputTemplate)
20+
.CreateBootstrapLogger();
21+
22+
try
23+
{
24+
Log.Information("Starting Console Host");
25+
26+
var app = Host
27+
.CreateDefaultBuilder(args)
28+
.ConfigureServices(services => services.AddHostedService<PrintTimeService>())
29+
.UseSerilog((context, services, configuration) => configuration
30+
.ReadFrom.Configuration(context.Configuration)
31+
)
32+
.Build();
33+
34+
await app.RunAsync();
35+
36+
return 0;
37+
}
38+
catch (Exception ex)
39+
{
40+
Log.Fatal(ex, "Host terminated unexpectedly");
41+
return 1;
42+
}
43+
finally
44+
{
45+
await Log.CloseAndFlushAsync();
46+
}
47+
}
48+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net7.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
<IsPackable>false</IsPackable>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<None Remove="appsettings.json" />
13+
</ItemGroup>
14+
15+
<ItemGroup>
16+
<Content Include="appsettings.json">
17+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
18+
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
19+
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
20+
</Content>
21+
</ItemGroup>
22+
23+
<ItemGroup>
24+
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.1" />
25+
<PackageReference Include="Serilog.Extensions.Hosting" Version="7.0.0" />
26+
<PackageReference Include="Serilog.Settings.Configuration" Version="7.0.0" />
27+
<PackageReference Include="Serilog.sinks.Console" Version="4.1.0" />
28+
</ItemGroup>
29+
30+
<ItemGroup>
31+
<ProjectReference Include="..\..\src\Serilog.Sinks.AzureTableStorage\Serilog.Sinks.AzureTableStorage.csproj" />
32+
</ItemGroup>
33+
34+
</Project>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"Serilog": {
3+
"Using": [ "Serilog.Sinks.Console", "Serilog.Sinks.AzureTableStorage" ],
4+
"MinimulLevel": {
5+
"Default": "Debug"
6+
},
7+
"WriteTo": [
8+
{
9+
"Name": "Console",
10+
"Args": {
11+
"outputTemplate": "{Timestamp:HH:mm:ss.fff} [{Level:u1}] {Message:lj}{NewLine}{Exception}"
12+
}
13+
},
14+
{
15+
"Name": "AzureTableStorage",
16+
"Args": {
17+
"connectionString": "DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://127.0.0.1:10000/devstoreaccount1;QueueEndpoint=http://127.0.0.1:10001/devstoreaccount1;TableEndpoint=http://127.0.0.1:10002/devstoreaccount1;",
18+
"propertyColumns": [ "SourceContext" ],
19+
"keyGenerator": "SampleConsoleApplication.CustomKeyGenerator, SampleConsoleApplication",
20+
"storageTableName": "ConsoleLog"
21+
}
22+
}
23+
],
24+
"Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId" ]
25+
},
26+
"AllowedHosts": "*"
27+
}

samples/SampleWebApplication/SampleWebApplication.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<TargetFramework>net7.0</TargetFramework>
55
<Nullable>enable</Nullable>
66
<ImplicitUsings>enable</ImplicitUsings>
7+
<IsPackable>false</IsPackable>
78
</PropertyGroup>
89

910
<ItemGroup>

0 commit comments

Comments
 (0)