I'm trying to implement the an Microsoft.Extensions.Logging.ILogger (copied below for brevity) on a F# Record
using System;
namespace Microsoft.Extensions.Logging
{
public interface ILogger
{
void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func<TState, Exception?, string> formatter);
bool IsEnabled(LogLevel logLevel);
IDisposable BeginScope<TState>(TState state);
}
}
This is the record implementation.
type ILoggerRcd<'TState> =
{
BeginScope : 'TState -> IDisposable
IsEnabled : LogLevel -> bool
Log : LogLevel * EventId * 'TState * exn * Func<'TState,exn,string> -> unit
}
interface ILogger with
override this.BeginScope(state : 'TState): IDisposable =
this.BeginScope (state)
override this.IsEnabled(logLevel: LogLevel): bool =
this.IsEnabled logLevel
override this.Log(logLevel: LogLevel, eventId: EventId, state : 'TState, ``exception``: exn, formatter: Func<'TState,exn,string>): unit =
this.Log(logLevel, eventId, state, ``exception``, formatter)
However, I'm getting this error on BeginScope: One or more of the explicit class or function type variables for this binding could not be generalized, because they were constrained to other types.
And this error on Log: The generic member 'Log' has been used at a non-uniform instantiation prior to this program point. Consider reordering the members so this member occurs first. Alternatively, specify the full type of the member explicitly, including argument types, return type and any additional generic parameters and constraints.
I've read through a few issues on fsharp compiler itself but nothing seems to be exactly this case I'm hitting. Is this something that can be done?