OctopusDeploy / Halibut

| Public | A secure communication stack for .NET using JSON-RPC over SSL.
Other
12 stars 44 forks source link

Adds support for sending logs to multiple destinations e.g. to both a in memory log as well as to something else which can be selective about what it logs. #485

Closed LukeButters closed 1 year ago

LukeButters commented 1 year ago

Background

[SC-55402]

Makes it possible to add a customer ILogFactory which logs specific events or records metrics while also still logging to the in memory logger.

Here is a very spelled out example of how to use the new classes:

// A thing that creates a new `InMemoryConnectionLog` on each call.
// Create a single one for performance to cache the LogProvider.GetLogger("Halibut")
ICreateNewILog singleInMemoryConntionLogCreator = new InMemoryConnectionLogCreator();

// These log writers only record and can never return logs.
ILogWriter logConnectionErrors = new LogConnectionErrors();
ILogWriter logSecurityEvents = new LogSecurityEvents();

Func<string, ILogWriter[]> logWriterCreator = prefix => new[] {logConnectionErrors, logSecurityEvents};

// Aggregate the logWriters and the in memory connection log creator
ICreateNewILog aggregateLoggerCreator = new AggregateLogWriterLogCreator(singleInMemoryConntionLogCreator, logWriterCreator);

// Now we need it to be a log factory, and for the ILogs to be cached.
ILogFactory logFactory = aggregateLoggerCreator.ToCachingLogFactory();

Changes:

How to review this PR

Quality :heavy_check_mark:

Pre-requisites

shortcut-integration[bot] commented 1 year ago

This pull request has been linked to Shortcut Story #55402: Get visibility into polling tentacles connecting to the queue..