Class LogCapture
A mechanism for capturing logger output in memory.
Inheritance
Implements
Namespace: LaunchDarkly.Logging
Assembly: LaunchDarkly.Logging.dll
Syntax
public class LogCapture : Object, ILogAdapter
Remarks
Calling Capture() provides a LogCapture
object that accumulates
all log output from any code that is configured to use it as the log adapter. This is mainly
intended for testing.
All messages that come to this object are captured regardless of the log level. If you want to filter out messages below a certain level, you can apply Level(ILogAdapter, LogLevel) and pass the resulting filtered adapter to whatever component will be doing the logging, in place of the original LogCapture object.
Examples
var logSink = Logs.Capture(); // ... execute some code that produces log output to this adapter var capturedMessages = sink.GetMessages();
Constructors
LogCapture()
Declaration
public LogCapture()
Methods
GetMessages()
Returns all captured messages.
Declaration
public List<LogCapture.Message> GetMessages()
Returns
Type | Description |
---|---|
System.Collections.Generic.List<LogCapture.Message> | a copy of the messages |
GetMessageStrings()
Returns all captured messages converted to strings, in the format "[LoggerName] LEVEL: text".
Declaration
public List<string> GetMessageStrings()
Returns
Type | Description |
---|---|
System.Collections.Generic.List<System.String> | a copy of the messages as strings |
HasMessageWithRegex(LogLevel, String)
Tests whether any captured message for the given level matches the given regular expression.
Declaration
public bool HasMessageWithRegex(LogLevel level, string pattern)
Parameters
Type | Name | Description |
---|---|---|
LogLevel | level | a log level |
System.String | pattern | a regular expression |
Returns
Type | Description |
---|---|
System.Boolean |
HasMessageWithText(LogLevel, String)
Tests whether any captured message for the given level exactly matches the given text.
Declaration
public bool HasMessageWithText(LogLevel level, string text)
Parameters
Type | Name | Description |
---|---|---|
LogLevel | level | a log level |
System.String | text | the desired message text |
Returns
Type | Description |
---|---|
System.Boolean |
NewChannel(String)
Called internally by the logging framework.
Declaration
public IChannel NewChannel(string name)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | the channel name |
Returns
Type | Description |
---|---|
IChannel | a new channel |
ToString()
Returns all of the captured log output as a string.
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
System.String | a string containing all captured log lines |