ewilliams
ewilliams
CC#
Created by ewilliams on 3/2/2024 in #help
Removing Logging Abstractions from Libraries
I'm creating a library that uses a builder patter. I don't want the library to process exceptions, create logs, etc. I want the consumer to be able to decide how to handle this aspect. Normally I would just stick some Serilog inside but I don't to force the dependancy onto others. My first thought is to provide a Func<Exception> as an option in the builders pipeline. Currently this works fine and could certainly create extension motioned that plug serilog into this. The default output dumps the console if the WithLogging function is not provided. Where I don't love this, closures. I feel like generally consumers will create a closure with choose. I'm targeting dotnet6 for this project (for a few reasons).
csharp
using var orderlyScanner = ScannerBuilder
.Configure()
.WithAddresses(ips)
.WithNodeTimeout(TimeSpan.FromMilliseconds(250))
.WithLogging(
exception =>
{
Console.WriteLine($"ORDERED ERROR: {exception.Message}");
},
message =>
{
Console.WriteLine($"ORDERED MESSAGE: {message}");
})
.Build();
csharp
using var orderlyScanner = ScannerBuilder
.Configure()
.WithAddresses(ips)
.WithNodeTimeout(TimeSpan.FromMilliseconds(250))
.WithLogging(
exception =>
{
Console.WriteLine($"ORDERED ERROR: {exception.Message}");
},
message =>
{
Console.WriteLine($"ORDERED MESSAGE: {message}");
})
.Build();
7 replies
CC#
Created by ewilliams on 11/30/2023 in #help
Source Generators In Nuget Packages
I’m working on a source generator and initially thought it wasn’t working. I was adding it to another project via a private nuget package. I ended up including a direct project reference and walla, the generator started kicking in and shows up in the analyzers. I cracked open the Nuget package and noticed there was no lib folder. So what’s the correct way to publish a nuget package for a source generator project? And what’s the correct way to include said nuget into another project.
7 replies