InMemoryLogEntry Class

Represents a log entry captured by an in-memory logger.

public sealed class InMemoryLogEntry

Example

var logger = InMemoryLogger.CreateLogger("sample");
logger.LogInformation("User {UserId} logged in", 123);

var log = logger.Logs.Informations.Single();
Assert.Equal("User 123 logged in", log.Message);
Assert.True(log.TryGetParameterValue("UserId", out var userId));
Assert.Equal(123, userId);

Properties

NameDescription
CategoryGets the logger category name.
CreatedAtGets the timestamp when the log entry was created.
EventIdGets the event identifier.
ExceptionGets the exception associated with the log entry.
LogLevelGets the log level.
MessageGets the formatted log message.
ScopesGets the list of scopes active when the log entry was created.
StateGets the state object associated with the log entry.

Gets the logger category name.

public string? Category { get; }

Property value

string?

Gets the timestamp when the log entry was created.

public DateTimeOffset CreatedAt { get; }

Property value

DateTimeOffset

Gets the event identifier.

public EventId EventId { get; }

Property value

EventId

Gets the exception associated with the log entry.

public Exception? Exception { get; }

Property value

Exception?

Gets the log level.

public LogLevel LogLevel { get; }

Property value

LogLevel

Gets the formatted log message.

public string Message { get; }

Property value

string

Gets the list of scopes active when the log entry was created.

public IReadOnlyList<object?> Scopes { get; }

Gets the state object associated with the log entry.

public object? State { get; }

Property value

object?

Methods

NameDescription
GetAllParameterValues(string)Gets all parameter values with the specified name from the state and scopes.
ToString()
TryGetParameterValue(string, object?)Tries to retrieve the first parameter value with the specified name from the state or scopes.

GetAllParameterValues(string)

InMemoryLogEntry.cs

Gets all parameter values with the specified name from the state and scopes.

public IEnumerable<object?> GetAllParameterValues(string name)

Parameters

name string
The parameter name to search for.

Returns

IEnumerable<object?> An enumerable of all matching parameter values.

public override string ToString()

Returns

string

No documentation is available.

TryGetParameterValue(string, object?)

InMemoryLogEntry.cs

Tries to retrieve the first parameter value with the specified name from the state or scopes.

public bool TryGetParameterValue(string name, out object? value)

Parameters

name string
The parameter name to search for.
value object?
When this method returns, contains the parameter value if found; otherwise, null.

Returns

bool true if a parameter with the specified name was found; otherwise, false.