FastMoq
Search Results for

    Show / Hide Table of Contents

    Class LoggingTestExtensions

    Provides framework-neutral logger registration helpers for test composition.

    Inheritance
    object
    LoggingTestExtensions
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: FastMoq.Extensions
    Assembly: FastMoq.Core.dll
    Syntax
    public static class LoggingTestExtensions

    Methods

    AddCapturedLoggerFactory(Mocker, ILoggerProvider, Action<ILoggingBuilder>?, bool)

    Creates and registers a capture-backed logger factory that adds a custom ILoggerProvider while still forwarding captured entries into the current Mocker instance.

    Declaration
    public static Mocker AddCapturedLoggerFactory(this Mocker mocker, ILoggerProvider provider, Action<ILoggingBuilder>? configureLogging = null, bool replace = false)
    Parameters
    Type Name Description
    Mocker mocker

    The current Mocker instance.

    ILoggerProvider provider

    A custom logger provider that processes all logged entries alongside FastMoq capture.

    Action<ILoggingBuilder> configureLogging

    Optional logging builder customization applied before the FastMoq capture provider is added.

    bool replace

    True to replace existing logger registrations.

    Returns
    Type Description
    Mocker

    The current Mocker instance.

    AddCapturedLoggerFactory(Mocker, Action<ILoggingBuilder>?, bool)

    Creates and registers a capture-backed logger factory along with direct ILogger and ILogger<TCategoryName> resolution support.

    Declaration
    public static Mocker AddCapturedLoggerFactory(this Mocker mocker, Action<ILoggingBuilder>? configureLogging = null, bool replace = false)
    Parameters
    Type Name Description
    Mocker mocker

    The current Mocker instance.

    Action<ILoggingBuilder> configureLogging

    Optional logging builder customization applied before the FastMoq capture provider is added.

    bool replace

    True to replace existing logger registrations.

    Returns
    Type Description
    Mocker

    The current Mocker instance.

    AddCapturedLoggerFactory(Mocker, Action<LogLevel, EventId, string, Exception?>, Action<ILoggingBuilder>?, bool)

    Creates and registers a capture-backed logger factory that mirrors captured log entries to the supplied sink while still forwarding them into the current Mocker instance.

    Declaration
    public static Mocker AddCapturedLoggerFactory(this Mocker mocker, Action<LogLevel, EventId, string, Exception?> sink, Action<ILoggingBuilder>? configureLogging = null, bool replace = false)
    Parameters
    Type Name Description
    Mocker mocker

    The current Mocker instance.

    Action<LogLevel, EventId, string, Exception> sink

    A sink that receives each captured log entry after FastMoq records it.

    Action<ILoggingBuilder> configureLogging

    Optional logging builder customization applied before the FastMoq capture provider is added.

    bool replace

    True to replace existing logger registrations.

    Returns
    Type Description
    Mocker

    The current Mocker instance.

    AddCapturedLoggerFactory(Mocker, Action<string>, Action<ILoggingBuilder>?, bool)

    Creates and registers a capture-backed logger factory that mirrors formatted log lines to the supplied writer while still forwarding captured entries into the current Mocker instance.

    Declaration
    public static Mocker AddCapturedLoggerFactory(this Mocker mocker, Action<string> lineWriter, Action<ILoggingBuilder>? configureLogging = null, bool replace = false)
    Parameters
    Type Name Description
    Mocker mocker

    The current Mocker instance.

    Action<string> lineWriter

    A line writer that receives a formatted representation of each captured log entry.

    Action<ILoggingBuilder> configureLogging

    Optional logging builder customization applied before the FastMoq capture provider is added.

    bool replace

    True to replace existing logger registrations.

    Returns
    Type Description
    Mocker

    The current Mocker instance.

    AddLoggerFactory(Mocker, ILoggerFactory, bool)

    Registers an ILoggerFactory and resolves ILogger services from that factory.

    Declaration
    public static Mocker AddLoggerFactory(this Mocker mocker, ILoggerFactory loggerFactory, bool replace = false)
    Parameters
    Type Name Description
    Mocker mocker

    The current Mocker instance.

    ILoggerFactory loggerFactory

    The logger factory to register.

    bool replace

    True to replace existing logger registrations.

    Returns
    Type Description
    Mocker

    The current Mocker instance.

    Remarks

    Prefer AddCapturedLoggerFactory(Mocker, Action<ILoggingBuilder>?, bool) when you want FastMoq to create and register the capture-backed factory for the current Mocker instance.

    AddLoggerFactory(Mocker, ILoggerProvider, Action<ILoggingBuilder>?, bool)

    Creates and registers a logger factory that adds a custom ILoggerProvider while still forwarding captured entries into the current Mocker instance.

    Declaration
    public static Mocker AddLoggerFactory(this Mocker mocker, ILoggerProvider provider, Action<ILoggingBuilder>? configureLogging = null, bool replace = false)
    Parameters
    Type Name Description
    Mocker mocker

    The current Mocker instance.

    ILoggerProvider provider

    A custom logger provider that processes all logged entries alongside FastMoq capture.

    Action<ILoggingBuilder> configureLogging

    Optional logging builder customization applied before the FastMoq capture provider is added.

    bool replace

    True to replace existing logger registrations.

    Returns
    Type Description
    Mocker

    The current Mocker instance.

    Remarks

    Use this when you want direct ILogger and ILogger<TCategoryName> resolution backed by a custom provider and FastMoq verification together.

    AddLoggerFactory(Mocker, Action<ILoggingBuilder>?, bool)

    Creates and registers a logger factory along with direct ILogger and ILogger<TCategoryName> resolution support.

    Declaration
    public static Mocker AddLoggerFactory(this Mocker mocker, Action<ILoggingBuilder>? configureLogging = null, bool replace = false)
    Parameters
    Type Name Description
    Mocker mocker

    The current Mocker instance.

    Action<ILoggingBuilder> configureLogging

    Optional logging builder customization applied before the FastMoq capture provider is added.

    bool replace

    True to replace existing logger registrations.

    Returns
    Type Description
    Mocker

    The current Mocker instance.

    Remarks

    Prefer AddCapturedLoggerFactory(Mocker, Action<ILoggingBuilder>?, bool) for new builder-based registrations that should capture log entries into the current Mocker instance. Use AddLoggerFactory(Mocker, ILoggerFactory, bool) when you already have a logger factory instance to register.

    Examples
    var mocker = new Mocker()
        .AddLoggerFactory();
    
    var logger = mocker.GetObject<ILogger<CheckoutService>>();
    logger.LogInformation("submitted order");
    
    mocker.VerifyLogged(LogLevel.Information, "submitted order");

    AddLoggerFactory(Mocker, Action<LogLevel, EventId, string, Exception?>, Action<ILoggingBuilder>?, bool)

    Creates and registers a logger factory that mirrors captured log entries to the supplied sink while still forwarding them into the current Mocker instance.

    Declaration
    public static Mocker AddLoggerFactory(this Mocker mocker, Action<LogLevel, EventId, string, Exception?> sink, Action<ILoggingBuilder>? configureLogging = null, bool replace = false)
    Parameters
    Type Name Description
    Mocker mocker

    The current Mocker instance.

    Action<LogLevel, EventId, string, Exception> sink

    A sink that receives each captured log entry after FastMoq records it.

    Action<ILoggingBuilder> configureLogging

    Optional logging builder customization applied before the FastMoq capture provider is added.

    bool replace

    True to replace existing logger registrations.

    Returns
    Type Description
    Mocker

    The current Mocker instance.

    AddLoggerFactory(Mocker, Action<string>, Action<ILoggingBuilder>?, bool)

    Creates and registers a logger factory that mirrors formatted log lines to the supplied writer while still forwarding captured entries into the current Mocker instance.

    Declaration
    public static Mocker AddLoggerFactory(this Mocker mocker, Action<string> lineWriter, Action<ILoggingBuilder>? configureLogging = null, bool replace = false)
    Parameters
    Type Name Description
    Mocker mocker

    The current Mocker instance.

    Action<string> lineWriter

    A line writer that receives a formatted representation of each captured log entry.

    Action<ILoggingBuilder> configureLogging

    Optional logging builder customization applied before the FastMoq capture provider is added.

    bool replace

    True to replace existing logger registrations.

    Returns
    Type Description
    Mocker

    The current Mocker instance.

    CreateLoggerFactory(Mocker, ILoggerProvider, Action<ILoggingBuilder>?)

    Creates a logger factory that adds a custom ILoggerProvider while still forwarding captured log entries into the current Mocker instance.

    Declaration
    public static ILoggerFactory CreateLoggerFactory(this Mocker mocker, ILoggerProvider provider, Action<ILoggingBuilder>? configureLogging = null)
    Parameters
    Type Name Description
    Mocker mocker

    The current Mocker instance.

    ILoggerProvider provider

    A custom logger provider that processes all logged entries alongside FastMoq capture.

    Action<ILoggingBuilder> configureLogging

    Optional logging builder customization applied before the FastMoq capture provider is added.

    Returns
    Type Description
    ILoggerFactory

    A logger factory that routes log entries to provider and LogEntries.

    Remarks

    Use this when test composition needs a first-class logging provider, such as xUnit output forwarding or custom filtering, without giving up FastMoq verification.

    CreateLoggerFactory(Mocker, Action<ILoggingBuilder>?)

    Creates a logger factory that forwards captured log entries into the current Mocker instance.

    Declaration
    public static ILoggerFactory CreateLoggerFactory(this Mocker mocker, Action<ILoggingBuilder>? configureLogging = null)
    Parameters
    Type Name Description
    Mocker mocker

    The current Mocker instance.

    Action<ILoggingBuilder> configureLogging

    Optional logging builder customization applied before the FastMoq capture provider is added.

    Returns
    Type Description
    ILoggerFactory

    A logger factory that writes into LogEntries through the current mocker callback.

    Examples
    var loggerFactory = Mocks.CreateLoggerFactory();
    var provider = Mocks.CreateTypedServiceProvider(services =>
    {
        services.AddSingleton(loggerFactory);
        services.AddSingleton(typeof(ILogger<>), typeof(Logger<>));
    });

    CreateLoggerFactory(Mocker, Action<LogLevel, EventId, string, Exception?>, Action<ILoggingBuilder>?)

    Creates a logger factory that mirrors captured log entries to the supplied sink while still forwarding them into the current Mocker instance.

    Declaration
    public static ILoggerFactory CreateLoggerFactory(this Mocker mocker, Action<LogLevel, EventId, string, Exception?> sink, Action<ILoggingBuilder>? configureLogging = null)
    Parameters
    Type Name Description
    Mocker mocker

    The current Mocker instance.

    Action<LogLevel, EventId, string, Exception> sink

    A sink that receives each captured log entry after FastMoq records it.

    Action<ILoggingBuilder> configureLogging

    Optional logging builder customization applied before the FastMoq capture provider is added.

    Returns
    Type Description
    ILoggerFactory

    A logger factory that mirrors captured entries to sink and LogEntries.

    Examples
    var loggerFactory = Mocks.CreateLoggerFactory((logLevel, eventId, message, exception) =>
    {
        output.WriteLine($"[{logLevel}] {message}");
    });

    CreateLoggerFactory(Mocker, Action<string>, Action<ILoggingBuilder>?)

    Creates a logger factory that mirrors formatted log lines to the supplied writer while still forwarding captured entries into the current Mocker instance.

    Declaration
    public static ILoggerFactory CreateLoggerFactory(this Mocker mocker, Action<string> lineWriter, Action<ILoggingBuilder>? configureLogging = null)
    Parameters
    Type Name Description
    Mocker mocker

    The current Mocker instance.

    Action<string> lineWriter

    A line writer that receives a formatted representation of each captured log entry.

    Action<ILoggingBuilder> configureLogging

    Optional logging builder customization applied before the FastMoq capture provider is added.

    Returns
    Type Description
    ILoggerFactory

    A logger factory that mirrors formatted log lines to lineWriter and raw entries to LogEntries.

    Examples
    var loggerFactory = Mocks.CreateLoggerFactory(output.WriteLine);

    SetupLoggerCallback(Mocker, Action<LogLevel, EventId, string, Exception?>)

    Registers an additional callback that receives log entries captured through the current Mocker instance.

    Declaration
    public static Mocker SetupLoggerCallback(this Mocker mocker, Action<LogLevel, EventId, string, Exception?> callback)
    Parameters
    Type Name Description
    Mocker mocker

    The current Mocker instance.

    Action<LogLevel, EventId, string, Exception> callback

    A callback that receives each captured log entry after FastMoq records it.

    Returns
    Type Description
    Mocker

    The current Mocker instance.

    Remarks

    Use this when the test already relies on FastMoq-managed logger capture and also needs to mirror normalized log output to a local sink. The callback observes formatted message text and exception data; it does not expose raw provider-specific logger state.

    Examples
    Mocks.SetupLoggerCallback((logLevel, eventId, message, exception) =>
    {
        output.WriteLine($"[{logLevel}] {message}");
    });

    SetupLoggerCallback(Mocker, Action<LogLevel, EventId, string>)

    Registers an additional callback that receives formatted log entries captured through the current Mocker instance.

    Declaration
    public static Mocker SetupLoggerCallback(this Mocker mocker, Action<LogLevel, EventId, string> callback)
    Parameters
    Type Name Description
    Mocker mocker

    The current Mocker instance.

    Action<LogLevel, EventId, string> callback

    A callback that receives each captured log entry after FastMoq records it.

    Returns
    Type Description
    Mocker

    The current Mocker instance.

    In this article
    Back to top
    Generated 2026-04-29 03:53 UTC