-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #142 from serilog-contrib/dev
prevent duplicate rowkey
- Loading branch information
Showing
9 changed files
with
243 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using Azure.Data.Tables; | ||
|
||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.DependencyInjection.Extensions; | ||
using Microsoft.Extensions.Hosting; | ||
|
||
using Serilog; | ||
|
||
namespace SampleStressTest; | ||
|
||
internal static class Program | ||
{ | ||
public static async Task<int> Main(string[] args) | ||
{ | ||
try | ||
{ | ||
var app = Host | ||
.CreateDefaultBuilder(args) | ||
.ConfigureServices(services => services | ||
.AddHostedService<StressTestService>() | ||
.TryAddSingleton(sp => | ||
{ | ||
var configuration = sp.GetRequiredService<IConfiguration>(); | ||
var connectionString = configuration.GetConnectionString("StorageAccount"); | ||
return new TableServiceClient(connectionString); | ||
}) | ||
) | ||
.UseSerilog((context, services, configuration) => configuration | ||
.ReadFrom.Services(services) | ||
.Enrich.FromLogContext() | ||
.WriteTo.AzureTableStorage( | ||
storageAccount: services.GetRequiredService<TableServiceClient>(), | ||
storageTableName: "SampleStressTest" | ||
) | ||
) | ||
.Build(); | ||
|
||
await app.RunAsync(); | ||
|
||
return 0; | ||
} | ||
catch (Exception ex) | ||
{ | ||
Log.Fatal(ex, "Host terminated unexpectedly"); | ||
return 1; | ||
} | ||
finally | ||
{ | ||
await Log.CloseAndFlushAsync(); | ||
} | ||
} | ||
} |
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,31 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<None Remove="appsettings.json" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Content Include="appsettings.json"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
<ExcludeFromSingleFile>true</ExcludeFromSingleFile> | ||
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory> | ||
</Content> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" /> | ||
<PackageReference Include="Serilog.Extensions.Hosting" Version="8.0.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\Serilog.Sinks.AzureTableStorage\Serilog.Sinks.AzureTableStorage.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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,62 @@ | ||
using Microsoft.Extensions.Hosting; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace SampleStressTest; | ||
|
||
public class StressTestService : IHostedLifecycleService | ||
{ | ||
private readonly ILogger<StressTestService> _logger; | ||
|
||
public StressTestService(ILogger<StressTestService> logger) | ||
{ | ||
this._logger = logger; | ||
} | ||
|
||
public Task StartAsync(CancellationToken cancellationToken) | ||
{ | ||
_logger.LogInformation("StartAsync Called"); | ||
return Task.CompletedTask; | ||
} | ||
|
||
public Task StartedAsync(CancellationToken cancellationToken) | ||
{ | ||
_logger.LogInformation("StartedAsync Called"); | ||
|
||
// hammer the logger | ||
var result = Parallel.For(1, 10000, index => | ||
{ | ||
_logger.LogInformation("Logging Loop {index}", index); | ||
_logger.LogInformation("Another Entry {index}", index); | ||
_logger.LogInformation("Duplicate Entry {index}", index); | ||
}); | ||
|
||
_logger.LogInformation("Stress test: {completed}", result.IsCompleted); | ||
|
||
return Task.CompletedTask; | ||
} | ||
|
||
public Task StartingAsync(CancellationToken cancellationToken) | ||
{ | ||
_logger.LogInformation("StartingAsync Called"); | ||
return Task.CompletedTask; | ||
} | ||
|
||
public Task StopAsync(CancellationToken cancellationToken) | ||
{ | ||
_logger.LogInformation("StopAsync Called"); | ||
return Task.CompletedTask; | ||
} | ||
|
||
public Task StoppedAsync(CancellationToken cancellationToken) | ||
{ | ||
_logger.LogInformation("StoppedAsync Called"); | ||
return Task.CompletedTask; | ||
} | ||
|
||
public Task StoppingAsync(CancellationToken cancellationToken) | ||
{ | ||
_logger.LogInformation("StoppingAsync Called"); | ||
return Task.CompletedTask; | ||
} | ||
|
||
} |
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 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Information", | ||
"Microsoft.AspNetCore": "Warning" | ||
} | ||
}, | ||
"ConnectionStrings": { | ||
"StorageAccount": "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;" | ||
}, | ||
"AllowedHosts": "*" | ||
} |
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
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
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