-
-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: send log events to log server (#234)
Fixes #192
- Loading branch information
1 parent
6db05e1
commit eef5d98
Showing
46 changed files
with
1,547 additions
and
424 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
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
image: Visual Studio 2019 | ||
image: Visual Studio 2022 | ||
|
||
environment: | ||
CODECOV_TOKEN: | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<RunSettings> | ||
<DataCollectionRunSettings> | ||
<DataCollectors> | ||
<DataCollector friendlyName="XPlat code coverage"> | ||
<Configuration> | ||
<Include>[Serilog.Sinks.Http]*</Include> | ||
</Configuration> | ||
</DataCollector> | ||
</DataCollectors> | ||
</DataCollectionRunSettings> | ||
</RunSettings> |
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
31 changes: 31 additions & 0 deletions
31
test/Serilog.Sinks.HttpTests.LogServer/Controllers/LogEventController.cs
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 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
using Serilog.Sinks.HttpTests.LogServer.Services; | ||
|
||
namespace Serilog.Sinks.HttpTests.LogServer.Controllers; | ||
|
||
[ApiController] | ||
public class LogEventController : ControllerBase | ||
{ | ||
private readonly HealthService healthService; | ||
private readonly LogEventService logEventService; | ||
|
||
public LogEventController(HealthService healthService, LogEventService logEventService) | ||
{ | ||
this.healthService = healthService; | ||
this.logEventService = logEventService; | ||
} | ||
|
||
[HttpPost] | ||
[Route("logs/{testId}")] | ||
public IActionResult Post(string testId, LogEventDto[] batch) | ||
{ | ||
if (!healthService.GetIsHealthy()) | ||
{ | ||
return StatusCode(StatusCodes.Status503ServiceUnavailable); | ||
} | ||
|
||
var logEvents = batch.Select(logEvent => logEvent.ToLogEvent()); | ||
logEventService.AddBatch(testId, logEvents); | ||
return NoContent(); | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
test/Serilog.Sinks.HttpTests.LogServer/Controllers/LogEventDto.cs
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,54 @@ | ||
using System.Text.Json.Serialization; | ||
using Serilog.Sinks.HttpTests.LogServer.Services; | ||
|
||
namespace Serilog.Sinks.HttpTests.LogServer.Controllers; | ||
|
||
public class LogEventDto | ||
{ | ||
[JsonPropertyName("Timestamp")] | ||
public DateTime Timestamp { get; set; } | ||
|
||
[JsonPropertyName("Level")] | ||
public string Level { get; set; } = "Information"; | ||
|
||
[JsonPropertyName("MessageTemplate")] | ||
public string? MessageTemplate { get; set; } | ||
|
||
[JsonPropertyName("RenderedMessage")] | ||
public string? RenderedMessage { get; set; } | ||
|
||
[JsonPropertyName("Properties")] | ||
public Dictionary<string, object>? Properties { get; set; } | ||
|
||
[JsonPropertyName("Renderings")] | ||
public Dictionary<string, LogEventRendering[]>? Renderings { get; set; } | ||
|
||
[JsonPropertyName("Exception")] | ||
public string? Exception { get; set; } | ||
|
||
public static LogEventDto From(LogEvent logEvent) | ||
{ | ||
return new LogEventDto | ||
{ | ||
Timestamp = logEvent.Timestamp, | ||
Level = logEvent.Level, | ||
MessageTemplate = logEvent.MessageTemplate, | ||
RenderedMessage = logEvent.RenderedMessage, | ||
Properties = logEvent.Properties, | ||
Renderings = logEvent.Renderings, | ||
Exception = logEvent.Exception, | ||
}; | ||
} | ||
|
||
public LogEvent ToLogEvent() | ||
{ | ||
return new LogEvent( | ||
Timestamp, | ||
Level, | ||
MessageTemplate, | ||
RenderedMessage, | ||
Properties, | ||
Renderings, | ||
Exception); | ||
} | ||
} |
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,11 @@ | ||
using Serilog.Sinks.HttpTests.LogServer; | ||
|
||
var builder = Host | ||
.CreateDefaultBuilder(args) | ||
.ConfigureWebHostDefaults(webBuilder => | ||
{ | ||
webBuilder.UseStartup<Startup>(); | ||
}); | ||
|
||
using var app = builder.Build(); | ||
app.Run(); |
29 changes: 29 additions & 0 deletions
29
test/Serilog.Sinks.HttpTests.LogServer/Properties/launchSettings.json
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,29 @@ | ||
{ | ||
"$schema": "https://json.schemastore.org/launchsettings.json", | ||
"iisSettings": { | ||
"windowsAuthentication": false, | ||
"anonymousAuthentication": true, | ||
"iisExpress": { | ||
"applicationUrl": "http://localhost:61894", | ||
"sslPort": 0 | ||
} | ||
}, | ||
"profiles": { | ||
"Serilog.Sinks.HttpTests.LogServer": { | ||
"commandName": "Project", | ||
"dotnetRunMessages": true, | ||
"launchBrowser": true, | ||
"applicationUrl": "http://localhost:5283", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
}, | ||
"IIS Express": { | ||
"commandName": "IISExpress", | ||
"launchBrowser": true, | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
test/Serilog.Sinks.HttpTests.LogServer/Serilog.Sinks.HttpTests.LogServer.csproj
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,9 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
</PropertyGroup> | ||
|
||
</Project> |
29 changes: 29 additions & 0 deletions
29
test/Serilog.Sinks.HttpTests.LogServer/Services/HealthService.cs
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,29 @@ | ||
namespace Serilog.Sinks.HttpTests.LogServer.Services; | ||
|
||
public class HealthService | ||
{ | ||
private readonly object syncRoot = new(); | ||
|
||
private bool isHealthy; | ||
|
||
public HealthService() | ||
{ | ||
isHealthy = true; | ||
} | ||
|
||
public bool GetIsHealthy() | ||
{ | ||
lock (syncRoot) | ||
{ | ||
return isHealthy; | ||
} | ||
} | ||
|
||
public void SetIsHealthy(bool isHealthy) | ||
{ | ||
lock (syncRoot) | ||
{ | ||
this.isHealthy = isHealthy; | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
test/Serilog.Sinks.HttpTests.LogServer/Services/LogEvent.cs
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,16 @@ | ||
namespace Serilog.Sinks.HttpTests.LogServer.Services; | ||
|
||
public record LogEvent( | ||
DateTime Timestamp, | ||
string Level, | ||
string? MessageTemplate, | ||
string? RenderedMessage, | ||
Dictionary<string, object>? Properties, | ||
Dictionary<string, LogEventRendering[]>? Renderings, | ||
string? Exception) | ||
{ | ||
} | ||
|
||
public record LogEventRendering( | ||
string Format, | ||
string Rendering); |
Oops, something went wrong.