Skip to end of metadata
Go to start of metadata

Instance based class to write log messages based on a given configuration. Messages are routed based on category.

Definition

public class LogWriter : ILogWriter, ILogFilterErrorHandler

Summary

The following table summarizes the members exposed in this class.

Public Constructors

LogWriter Constructor() Initializes a new instance of the LogWriter class.
LogWriter Constructor(string) Initializes a new instance of the LogWriter class with the specified default category.

Public Properties

AllEventsTraceSource Gets all events trace source.
CategoryFilters Gets the category filters.
ErrorsTraceSource Gets the errors trace source.
FilterMode Gets or sets the filter mode.
Filters Gets the filters.
Formatter Gets or sets the log formatter.
NotProcessedTraceSource Gets the not processed trace source.
RootFilterLevel Gets or sets the root filter level.
TraceSources Gets the LogSource mappings available for the LogWriter.

Constants

LogWriterFailureEventId EventID used on LogEntries that occur when internal LogWriter mechanisms fail.

Static Methods

ResetLockTimeouts() Reset lock timeouts to thier original values.
SetLockTimeouts(int, int) Sets the lock timeouts for the writer.

Public Methods

AddCategory(string, SourceLevel) Adds the category-severity filter.
Dispose() Releases the resources used by the LogWriter.
FilterCheckingFailed(Exception, LogEntry, ILogFilter) This method supports the Enterprise Library infrastructure and is not intended to be used directly from your code. Performs any action to handle an error during checking.
FlushContextItems() Empties the context items dictionary.
GetFilter<T>() Returns the filter of type <typeparamref name="T" />.
GetFilter<T>(string) Returns the filter of type <typeparamref name="T" /> named <paramref name="name" />.
GetFilter(string) Returns the filter named <paramref name="name" />.
GetMatchingTraceSources(LogEntry) Gets a list of LogSource objects for the log entry.
GetTraceListeners<T>() Gets the trace listeners with the specified type.
IsLoggingEnabled() Queries whether logging is enabled.
IsTracingEnabled() Queries whether tracing is enabled.
RegisterDefaultTraceListener(TraceListener) Registers the default trace listener.
SetContextItem(object, object) Adds a key/value pair to the CallContext dictionary. Context items will be recorded with every log entry.
ShouldLog(LogEntry) Queries whether a LogEntry shold be logged.
Write(LogEntry) Writes a new log entry as defined in the LogEntry parameter.

Public Constructors

public LogWriter()

Initializes a new instance of the LogWriter class.

public LogWriter(string defaultCategory)

Initializes a new instance of the LogWriter class with the specified default category.

Parameters

defaultCategory The default category.

Public Properties

public LogSource AllEventsTraceSource { get; }

Gets all events trace source.

public Dictionary<string, SourceLevel> CategoryFilters { get; }

Gets the category filters.

public LogSource ErrorsTraceSource { get; }

Gets the errors trace source.

public CategoryFilterMode FilterMode { get; set; }

Gets or sets the filter mode.

public ICollection<ILogFilter> Filters { get; }

Gets the filters.

public ILogFormatter Formatter { get; set; }

Gets or sets the log formatter.

public LogSource NotProcessedTraceSource { get; }

Gets the not processed trace source.

public SourceLevel RootFilterLevel { get; set; }

Gets or sets the root filter level.

public IDictionary<string, LogSource> TraceSources { get; }

Gets the LogSource mappings available for the LogWriter.

Constants

public const int LogWriterFailureEventId

EventID used on LogEntries that occur when internal LogWriter mechanisms fail.

Static Methods

public static void ResetLockTimeouts()

Reset lock timeouts to thier original values.

public static void SetLockTimeouts(int readerTimeout, int writerTimeout)

Sets the lock timeouts for the writer.

Parameters

readerTimeout The reader timeout.
writerTimeout The writer timeout.

Public Methods

public void AddCategory(string category, SourceLevel level)

Adds the category-severity filter.

Parameters

category The category.
level The level.

public void Dispose()

Releases the resources used by the LogWriter.

public bool FilterCheckingFailed(Exception ex, LogEntry logEntry, ILogFilter filter)

This method supports the Enterprise Library infrastructure and is not intended to be used directly from your code. Performs any action to handle an error during checking.

Parameters

ex The exception raised during filter evaluation.
logEntry The log entry being evaluated.
filter The fiter that raised the exception.

Return Types

True signaling processing should continue.

public void FlushContextItems()

Empties the context items dictionary.

public T GetFilter<T>()

Returns the filter of type <typeparamref name="T" />.

Type Parameters

T The type of filter requiered.

Return Types

The instance of <typeparamref name="T" /> in the filters collection, or if there is no such instance.

public T GetFilter<T>(string name)

Returns the filter of type <typeparamref name="T" /> named <paramref name="name" />.

Type Parameters

T The type of filter required.

Parameters

name The name of the filter required.

Return Types

The instance of <typeparamref name="T" /> named <paramref name="name" /> in the filters collection, or if there is no such instance.

public ILogFilter GetFilter(string name)

Returns the filter named <paramref name="name" />.

Parameters

name The name of the filter required.

Return Types

The filter named <paramref name="name" /> in the filters collection, or if there is no such filter.

public IEnumerable<LogSource> GetMatchingTraceSources(LogEntry logEntry)

Gets a list of LogSource objects for the log entry.

Parameters

logEntry The LogEntry to get the matching trace sources.

Return Types

A collection of LogSource objects.

public IEnumerable<T> GetTraceListeners<T>()

Gets the trace listeners with the specified type.

Type Parameters

T The trace listener type.

public bool IsLoggingEnabled()

Queries whether logging is enabled.

Return Types

true if logging is enabled.

public bool IsTracingEnabled()

Queries whether tracing is enabled.

Return Types

true if tracing is enabled.

public void RegisterDefaultTraceListener(TraceListener traceListener)

Registers the default trace listener.

Parameters

traceListener The trace listener.

public void SetContextItem(object key, object value)

Adds a key/value pair to the CallContext dictionary. Context items will be recorded with every log entry.

Parameters

key Hashtable key
value Value. Objects will be serialized.

public bool ShouldLog(LogEntry log)

Queries whether a LogEntry shold be logged.

Parameters

log The log entry to check.

Return Types

true if the entry should be logged.

public void Write(LogEntry log)

Writes a new log entry as defined in the LogEntry parameter.

Parameters

log Log entry object to write.
  • No labels