Remove the event listener

pull/178/head
David Fowler 2022-11-05 08:44:35 -07:00
parent 27daaffe38
commit 89d6e747ec
1 changed files with 0 additions and 38 deletions

View File

@ -1,38 +0,0 @@
using System.Collections.Concurrent;
using System.Diagnostics.Tracing;
// Just for debugging things
class OtelListener : EventListener
{
public static ILoggerFactory _factory;
private ConcurrentDictionary<string, ILogger> _loggerMap = new();
public OtelListener()
{
}
protected override void OnEventSourceCreated(EventSource eventSource)
{
if (eventSource.Name.StartsWith("OpenTelemetry"))
{
if (_loggerMap.TryGetValue(eventSource.Name, out _)) return;
ILogger CreateAndRegister(string name)
{
var l = _factory.CreateLogger(name);
base.EnableEvents(eventSource, EventLevel.LogAlways, EventKeywords.All);
return l;
}
var logger = _loggerMap.AddOrUpdate(eventSource.Name, CreateAndRegister, (name, existing) => existing);
}
base.OnEventSourceCreated(eventSource);
}
protected override void OnEventWritten(EventWrittenEventArgs eventData)
{
if (_loggerMap[eventData.EventSource.Name] is { } logger)
{
logger.Log(LogLevel.Information, eventData.Message, (eventData.Payload?.ToArray() ?? Array.Empty<object>()));
}
}
}