Skip to content

Make IRichTextBox public for Dependency InjectionΒ #18

@LazerFX

Description

@LazerFX

I'm writing an application (Purely for myself, I don't intend to use this in production or anything), but I'd like to use RichTextBox sink - saves me having to have a console or spin up a file dropper or something like that every time I want to see logger output. However, the application is written in .NET 5 WPF, using Dependency Injection throughout. Serilog is registered through DI.

The issue is that I cannot configure the Logger after application start because it uses the UseSerilog extension on the IHostBuilder interface, but at that point the RichTextBox I want to target isn't instantiated.

My solution would be simple - instantiate an IRichTextBox interface that can be set up as a UseSingleton value. Then, I can inject that into the target Window, add the RichTextBox itself to it, and do a pass-through from the interface to the actual controls on the RichTextBox. I can't do this at the moment, as the IRichTextBox interface and the WriteTo.RichTextBox extension method that uses the IRichTextBox is internal sealed.

Before I go ahead and do this and put a PR together with the changes, I just thought I'd push this out for comment from the team working on this to see if anyone has any suggestions - maybe there's a better way of doing this?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions