Class LogCapture
A mechanism for capturing logger output in memory.
Implements
Inherited Members
Namespace: LaunchDarkly.Logging
Assembly: LaunchDarkly.Logging.dll
Syntax
public class LogCapture : 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
GetMessageStrings()
Returns all captured messages converted to strings, in the format "[LoggerName] LEVEL: text".
Declaration
public List<string> GetMessageStrings()
Returns
Type | Description |
---|---|
List<string> | a copy of the messages as strings |
GetMessages()
Returns all captured messages.
Declaration
public List<LogCapture.Message> GetMessages()
Returns
Type | Description |
---|---|
List<LogCapture.Message> | a copy of the messages |
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 |
string | pattern | a regular expression |
Returns
Type | Description |
---|---|
bool |
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 |
string | text | the desired message text |
Returns
Type | Description |
---|---|
bool |
NewChannel(string)
Called internally by the logging framework.
Declaration
public IChannel NewChannel(string name)
Parameters
Type | Name | Description |
---|---|---|
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 |
---|---|
string | a string containing all captured log lines |