Serilog.Sinks.MemorySink 0.1.1-alpha

This is a prerelease version of Serilog.Sinks.MemorySink.
dotnet add package Serilog.Sinks.MemorySink --version 0.1.1-alpha                
NuGet\Install-Package Serilog.Sinks.MemorySink -Version 0.1.1-alpha                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Serilog.Sinks.MemorySink" Version="0.1.1-alpha" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Serilog.Sinks.MemorySink --version 0.1.1-alpha                
#r "nuget: Serilog.Sinks.MemorySink, 0.1.1-alpha"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Serilog.Sinks.MemorySink as a Cake Addin
#addin nuget:?package=Serilog.Sinks.MemorySink&version=0.1.1-alpha&prerelease

// Install Serilog.Sinks.MemorySink as a Cake Tool
#tool nuget:?package=Serilog.Sinks.MemorySink&version=0.1.1-alpha&prerelease                

🧵 Serilog.Sinks.MemorySink

A Serilog sink that store log events in memory. You can retrieve these logs and render them in your own log viewer.

The sample app shows how to create a simple log viewer using WinUI 3.

Log viewer sample screenshotGetting started

Install Serilog.Sinks.MemorySink:

dotnet add package Serilog.Sinks.MemorySink

Create a logger configuration:

Log.Logger = new LoggerConfiguration()
    .WriteTo.MemorySink(out ILogSource<Serilog.Events.LogEvent> logSource)
    .CreateLogger();

Retrieve logs:

var logs = await logSource.GetLogs(startIndex, requiredCount, cancellationToken);

⚙️Custom log item, options and exception handling

To use a custom log item, you need to provide a log event converter:

public record LogItem(DateTimeOffset Timestamp, LogEventLevel Level, string Message);
Log.Logger = new LoggerConfiguration()
    .WriteTo.MemorySink(
        out ILogSource<LogItem> logSource,
        options =>
        {
            options.LogEventConverter = logEvent =>
            {
                return new LogItem(logEvent.Timestamp, logEvent.Level, logEvent.MessageTemplate.Text);
            };
            options.MaxLogsCount = 100_000;
            options.OnException = ex =>
            {
                // Handle sink processing exception.
            };
        })
        .CreateLogger();
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.1.1-alpha 118 4/26/2024
0.1.0-alpha 74 4/19/2024