Frank.PulseFlow.Logging 2.0.0

There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package Frank.PulseFlow.Logging --version 2.0.0                
NuGet\Install-Package Frank.PulseFlow.Logging -Version 2.0.0                
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.0" />                
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.0                
#r "nuget: Frank.PulseFlow.Logging, 2.0.0"                
#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.0

// Install Frank.PulseFlow.Logging as a Cake Tool
#tool nuget:?package=Frank.PulseFlow.Logging&version=2.0.0                

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 80 3/3/2024
2.0.0 222 2/4/2024
1.7.7-preview 62 2/4/2024
1.7.0 422 1/21/2024
1.6.5-preview 63 1/21/2024
1.6.4-preview 70 1/21/2024
1.6.3-preview 63 1/19/2024
1.6.0 224 1/14/2024
1.5.0 494 12/31/2023
1.4.1-preview 68 12/31/2023