Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Rin captures a request and response. Also, it captures logs while processing a r

- Built-in `Microsoft.Extensions.Logging.ILogger` integration
- log4net Appender
- Serilog Sink

### Save and export request/response
You can replay a request easily using cURL and LINQPad.
Expand Down
6 changes: 6 additions & 0 deletions Rin.sln
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Rin.Extensions.Log4NetAppen
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Rin.Extensions.MagicOnion", "src\Rin.Extensions.MagicOnion\Rin.Extensions.MagicOnion.csproj", "{F73CA06F-80DB-46B4-AEAB-A01AA6311C2B}"
EndProject
Project("{001C71B0-2657-479C-82E3-5888F4CB727A}") = "Rin.Extensions.Serilog.Sink", "src\Rin.Extensions.Serilog.Sink\Rin.Extensions.Serilog.Sink.csproj", "{92012EED-64AD-46BE-908E-79B98FDE483B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -65,6 +67,10 @@ Global
{F73CA06F-80DB-46B4-AEAB-A01AA6311C2B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F73CA06F-80DB-46B4-AEAB-A01AA6311C2B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F73CA06F-80DB-46B4-AEAB-A01AA6311C2B}.Release|Any CPU.Build.0 = Release|Any CPU
{92012EED-64AD-46BE-908E-79B98FDE483B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{92012EED-64AD-46BE-908E-79B98FDE483B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{92012EED-64AD-46BE-908E-79B98FDE483B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{92012EED-64AD-46BE-908E-79B98FDE483B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
44 changes: 44 additions & 0 deletions src/Rin.Extensions.Serilog.Sink/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
Serilog sink for writings trace info to Rin.

# Syntax description

There are 2 ways to add Serilog support. Both ways give the same result.

## Code
```csharp
Log.Logger = new LoggerConfiguration()
.WriteTo.Console()
.WriteTo.Rin(LogEventLevel.Information)
.CreateLogger();
```

## Configuration
```json
{
"Serilog": {
"Using": [
"Serilog.Sinks.Console",
"Rin.Extensions.Serilog.Sink"
],
"MinimumLevel": "Debug",
"WriteTo": [
{
"Name": "Console"
},
{
"Name": "Rin",
"Args": {
"restrictedToMinimumLevel": "Information"
}
}
]
}
}
```

```csharp
var builder = WebApplication.CreateBuilder();
Log.Logger = new LoggerConfiguration()
.ReadFrom.Configuration(builder.Configuration)
.CreateLogger();
```
18 changes: 18 additions & 0 deletions src/Rin.Extensions.Serilog.Sink/Rin.Extensions.Serilog.Sink.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<LangVersion>10.0</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Serilog" Version="3.1.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Rin\Rin.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Rin.Extensions.Serilog.Sink.Sinks;
using Serilog;
using Serilog.Configuration;
using Serilog.Events;

namespace Rin.Extensions.Serilog.Sink;

public static class RinLoggerConfigurationExtensions
{
public static LoggerConfiguration Rin(
this LoggerSinkConfiguration loggerSinkConfiguration,
LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum)
{
var sink = new RinSink();
return loggerSinkConfiguration.Sink(sink, restrictedToMinimumLevel);
}
}
24 changes: 24 additions & 0 deletions src/Rin.Extensions.Serilog.Sink/Sinks/RinSink.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using Rin.Core.Record;
using Serilog.Core;
using Serilog.Events;

namespace Rin.Extensions.Serilog.Sink.Sinks;

public class RinSink : ILogEventSink
{
public void Emit(LogEvent logEvent)
{
TimelineStamp.Stamp(ToLogLevelName(logEvent.Level), TimelineEventCategory.Trace, logEvent.RenderMessage());
}

private static string ToLogLevelName(LogEventLevel level)
{
if (level <= LogEventLevel.Verbose) return "Trace";
if (level <= LogEventLevel.Debug) return "Debug";
if (level <= LogEventLevel.Information) return "Information";
if (level <= LogEventLevel.Warning) return "Warning";
if (level <= LogEventLevel.Error) return "Error";
return "Critical";
}
}