InMemoryLogCollection Class
Represents a thread-safe collection of log entries captured by in-memory loggers.
public sealed class InMemoryLogCollection : IEnumerable<InMemoryLogEntry>, IEnumerableExample
var logger = InMemoryLogger.CreateLogger("sample");
logger.LogInformation("Application started");
logger.LogError("Error while processing the request");
// Filter by log level
var errors = logger.Logs.Errors;
var infos = logger.Logs.Informations;
Assert.Single(errors);
Assert.Single(infos);
// Search for specific entries
var entry = logger.Logs.Find(log => log.Message.StartsWith("Error", StringComparison.Ordinal));
Assert.NotNull(entry);
Assert.Equal(LogLevel.Error, entry.LogLevel);- Implements
Nested types
| Name | Description |
|---|---|
| InMemoryLogCollection.Enumerator | Enumerates the elements of a InMemoryLogCollection. |
Constructors
| Name | Description |
|---|---|
| InMemoryLogCollection() |
InMemoryLogCollection()
InMemoryLogCollection.cspublic InMemoryLogCollection()No documentation is available.
Properties
| Name | Description |
|---|---|
| Count | Gets the number of log entries in the collection. |
| Criticals | Gets all log entries with log level LogLevel.Critical. |
| Debugs | Gets all log entries with log level LogLevel.Debug. |
| Errors | Gets all log entries with log level LogLevel.Error. |
| Informations | Gets all log entries with log level LogLevel.Information. |
| Traces | Gets all log entries with log level LogLevel.Trace. |
| Warnings | Gets all log entries with log level LogLevel.Warning. |
Criticals
InMemoryLogCollection.csGets all log entries with log level LogLevel.Critical.
public IEnumerable<InMemoryLogEntry> Criticals { get; }Property value
Debugs
InMemoryLogCollection.csGets all log entries with log level LogLevel.Debug.
public IEnumerable<InMemoryLogEntry> Debugs { get; }Property value
Errors
InMemoryLogCollection.csGets all log entries with log level LogLevel.Error.
public IEnumerable<InMemoryLogEntry> Errors { get; }Property value
Informations
InMemoryLogCollection.csGets all log entries with log level LogLevel.Information.
public IEnumerable<InMemoryLogEntry> Informations { get; }Property value
Traces
InMemoryLogCollection.csGets all log entries with log level LogLevel.Trace.
public IEnumerable<InMemoryLogEntry> Traces { get; }Property value
Warnings
InMemoryLogCollection.csGets all log entries with log level LogLevel.Warning.
public IEnumerable<InMemoryLogEntry> Warnings { get; }Property value
Methods
| Name | Description |
|---|---|
| Clear() | Removes all log entries from the collection. |
| Contains(Func<InMemoryLogEntry, bool>) | Determines whether the collection contains any log entry that matches the specified predicate. |
| Find(Func<InMemoryLogEntry, bool>) | Searches for the first log entry that matches the specified predicate. |
| GetEnumerator() | |
| System.Collections.Generic.IEnumerable<Meziantou.Extensions.Logging.InMemory.InMemoryLogEntry>.GetEnumerator() | |
| System.Collections.IEnumerable.GetEnumerator() | |
| ToString() |
Clear()
InMemoryLogCollection.csRemoves all log entries from the collection.
public void Clear()Remarks
An enumeration already in progress keeps walking the entries it started on; it is not invalidated.
Contains(Func<InMemoryLogEntry, bool>)
InMemoryLogCollection.csDetermines whether the collection contains any log entry that matches the specified predicate.
public bool Contains(Func<InMemoryLogEntry, bool> predicate)Parameters
predicateFunc<InMemoryLogEntry, bool>- The function to test each log entry for a condition.
Returns
bool true if any log entry matches the predicate; otherwise, false.
Find(Func<InMemoryLogEntry, bool>)
InMemoryLogCollection.csSearches for the first log entry that matches the specified predicate.
public InMemoryLogEntry? Find(Func<InMemoryLogEntry, bool> predicate)Parameters
predicateFunc<InMemoryLogEntry, bool>- The function to test each log entry for a condition.
Returns
InMemoryLogEntry? The first log entry that matches the predicate, or null if no match is found.
GetEnumerator()
InMemoryLogCollection.cspublic InMemoryLogCollection.Enumerator GetEnumerator()No documentation is available.
System.Collections.Generic.IEnumerable<Meziantou.Extensions.Logging.InMemory.InMemoryLogEntry>.GetEnumerator()
InMemoryLogCollection.csIEnumerator<InMemoryLogEntry> IEnumerable<InMemoryLogEntry>.GetEnumerator()No documentation is available.