Assembly: CuttingEdge.Logging (in CuttingEdge.Logging.dll)
Syntax
| Visual Basic (Declaration) |
|---|
Public Class MemoryLoggingProvider _ Inherits LoggingProviderBase |
| C# |
|---|
public class MemoryLoggingProvider : LoggingProviderBase |
| Visual C++ |
|---|
public ref class MemoryLoggingProvider : public LoggingProviderBase |
| JavaScript |
|---|
CuttingEdge.Logging.MemoryLoggingProvider = function(); Type.createClass( 'CuttingEdge.Logging.MemoryLoggingProvider', CuttingEdge.Logging.LoggingProviderBase); |
Remarks
When the MemoryLoggingProvider succeeds storing the event in the internal list, the Log method will return an Int32 with the index of the logging event in the internal collection. Note that when Clear is called, counting will start over. Please note that the provider will return null when the event was not stored. This happens in the following situations:
- The provider's Threshold was set higher than the event's Severity.
- There was an exception logging the event, but it was logged successfully to the FallbackProvider.
This class is used by the Logger class to provide Logging services that logs to an in-memory cache.
WARNING: This class is only suitable for debugging purposes. The internal cache that the MemoryLoggingProvider will hold is not cleared automatically and will grow unlimited. This could lead to OutOfMemoryExceptions in production environments.
The table below shows the list of valid attributes for the MemoryLoggingProvider configuration:
| Attribute | Description |
|---|---|
| name | The name of the provider. This attribute is mandatory. |
| description | A description of the provider. This attribute is optional. |
| fallbackProvider | A fallback provider that this provider will use when logging failed. The value must contain the name of an existing logging provider. This attribute is optional. |
| threshold | The logging threshold. The threshold limits the number of events logged. The threshold can be defined as follows: Debug < Information < Warning < Error < Critical. i.e., When the threshold is set to Information, events with a severity of Debug will not be logged. When no value is specified, all events are logged. This attribute is optional. |
Examples
Copy Code | |
|---|---|
|
<?xml version="1.0"?> <configuration> <configSections> <section name="logging" type="CuttingEdge.Logging.LoggingSection, CuttingEdge.Logging" allowDefinition="MachineToApplication" /> </configSections> <logging defaultProvider="MemoryLoggingProvider"> <providers> <add name="MemoryLoggingProvider" type="CuttingEdge.Logging.MemoryLoggingProvider, CuttingEdge.Logging" description="Memory logging provider" threshold="Debug" /> </providers> </logging> </configuration> | |
Copy Code | |
|---|---|
|
Logger.Log(LoggingEventType.Error, "This is an error"); MemoryLoggingProvider memoryLogger = (MemoryLoggingProvider)Logger.Provider; foreach (LogEntry entry in memoryLogger.GetLoggedEntries()) { Console.WriteLine(entry); } // Clear the cache memoryLogger.Clear(); | |
Inheritance Hierarchy
System.Configuration.Provider..::.ProviderBase
CuttingEdge.Logging..::.LoggingProviderBase
CuttingEdge.Logging..::.MemoryLoggingProvider