-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSharedLogger.cs
More file actions
27 lines (22 loc) · 978 Bytes
/
SharedLogger.cs
File metadata and controls
27 lines (22 loc) · 978 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
using Microsoft.Extensions.Logging;
using System;
using System.Runtime.InteropServices.Marshalling;
#pragma warning disable CS8500
namespace Hi3Helper.Plugin.Core;
internal class SharedLogger : ILogger
{
public unsafe void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func<TState, Exception?, string> formatter)
{
if (SharedStatic.InstanceLoggerCallback == null)
{
return;
}
string formattedString = exception != null ? formatter(state, exception) + "\r\n" + exception : formatter(state, exception);
fixed (char* formatterStrP = &Utf16StringMarshaller.GetPinnableReference(formattedString))
{
SharedStatic.InstanceLoggerCallback(&logLevel, &eventId, formatterStrP, formattedString.Length);
}
}
public bool IsEnabled(LogLevel logLevel) => true;
public IDisposable? BeginScope<TState>(TState state) where TState : notnull => null;
}