Frank.PulseFlow.Logging 2.0.8-preview

This is a prerelease version of Frank.PulseFlow.Logging.
dotnet add package Frank.PulseFlow.Logging --version 2.0.8-preview
NuGet\Install-Package Frank.PulseFlow.Logging -Version 2.0.8-preview
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="Frank.PulseFlow.Logging" Version="2.0.8-preview" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Frank.PulseFlow.Logging --version 2.0.8-preview
#r "nuget: Frank.PulseFlow.Logging, 2.0.8-preview"
#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 Frank.PulseFlow.Logging as a Cake Addin
#addin nuget:?package=Frank.PulseFlow.Logging&version=2.0.8-preview&prerelease

// Install Frank.PulseFlow.Logging as a Cake Tool
#tool nuget:?package=Frank.PulseFlow.Logging&version=2.0.8-preview&prerelease

Frank.PulseFlow.Logging

This library provides a simple logger for use in .NET applications. It uses the Microsoft.Extensions.Logging library backed by Frank.PulseFlow for logging. It will log to the console by default, but can add one or more IFlow's to do whatever you want with the log messages. A common use case is to log to a file or a database, and because Frank.PulseFlow is thread-safe, you can do so without worrying about concurrency issues like file locks, or the overhead of waiting for a lock.

Usage

using Frank.PulseFlow.Logging;

public class Program
{
    public static async Task Main(string[] args)
    {
        var builder = new HostBuilder()
        .ConfigureLogging((hostContext, logging) =>
        {
            logging.AddPulseFlow();
        })
        .ConfigureServices((hostContext, services) =>
        {
            services.AddPulseFlow<FileLoggerFlow>();
        });
        .Build();
        
        await builder.RunAsync();
    }
}

public class FileLoggerFlow(IOptions<FileLoggerSettings> options) : IFlow
{
    private readonly FileLoggerSettings _settings = options.Value;
    
    public async Task HandleAsync(IPulse pulse, CancellationToken cancellationToken)
    {
        var thing = pulse as LogPulse;
        await File.AppendAllTextAsync(_settings.LogPath, thing! + Environment.NewLine, cancellationToken);
    }

    public bool CanHandle(Type pulseType) => pulseType == typeof(LogPulse);
}

public class FileLoggerSettings
{
    public string LogPath { get; set; } = "../../../../logs.log";
}

Configuration

The AddPulseFlow method has a few overloads that allow you to configure the logger. The default configuration is to log to the console, but you can add one or more IFlow's to the logger to do whatever you want with the log messages. A common use case is to log to a file or a database, and because Frank.PulseFlow is thread-safe, you can do so without worrying about concurrency issues like file locks, or the overhead of waiting for a lock.

Contributing

Contributions are welcome! Please see create an issue before submitting a pull request to discuss the changes you would like to make.

License

This library is licensed under the MIT license. See the LICENSE file for more information.

Product Compatible and additional computed target framework versions.
.NET 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 (1)

Showing the top 1 NuGet packages that depend on Frank.PulseFlow.Logging:

Package Downloads
Frank.Testing.Logging

Loggers for the Microsoft.Extensions.Logging framework wrapping the xUnit.net ITestOutputHelper.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.0.8-preview 73 3/3/2024
2.0.0 189 2/4/2024
1.7.7-preview 60 2/4/2024
1.7.0 415 1/21/2024
1.6.5-preview 61 1/21/2024
1.6.4-preview 69 1/21/2024
1.6.3-preview 62 1/19/2024
1.6.0 217 1/14/2024
1.5.0 489 12/31/2023
1.4.1-preview 66 12/31/2023