Table of Contents

Class LogContext

Namespace
CMS.EventLog
Assembly
CMS.EventLog.dll

Provides the context for logging asynchronous events.

[Obsolete("Member is deprecated and will be removed in next version.")]
[ObsoleteSince(28, 0)]
public class LogContext : ILogContext, INotCopyThreadItem
Inheritance
object
LogContext
Implements
Extension Methods

Constructors

LogContext()

Constructor - Registers the context within request.

public LogContext()

LogContext(Guid)

Constructor - Registers the context within request.

public LogContext(Guid logGuid)

Parameters

logGuid Guid

Fields

mEvent

Info object containing event.

protected EventLogInfo mEvent

Field Value

EventLogInfo

mLog

Current log.

protected StringBuilder mLog

Field Value

StringBuilder

mLogGuid

Logs GUID.

protected Guid mLogGuid

Field Value

Guid

mLogSingleEvents

Indicates whether to log events one by one to event log.

protected bool? mLogSingleEvents

Field Value

bool?

mLogs

Table of existing logs [GUID] -> [LogContext]

protected static SafeDictionary<Guid, LogContext> mLogs

Field Value

SafeDictionary<Guid, LogContext>

mMultipleOperationEventCode

Explicit event log code used when LogSingleEvents is false (case of multiple logging).

protected string mMultipleOperationEventCode

Field Value

string

Properties

Current

Gets or sets current log context.

public static LogContext Current { get; set; }

Property Value

LogContext

Event

Info object of type EventLogInfo.

public EventLogInfo Event { get; set; }

Property Value

EventLogInfo

EventURL

URL of event.

public string EventURL { get; set; }

Property Value

string

IPAddress

IP address of client.

public string IPAddress { get; set; }

Property Value

string

Log

Gets the current log.

public string Log { get; set; }

Property Value

string

LogAlways

If true, the context always logs regardless of the action context settings

public bool LogAlways { get; set; }

Property Value

bool

LogGuid

Logs guid.

public Guid LogGuid { get; set; }

Property Value

Guid

LogSingleEvents

Indicates whether to log events one by one to event log.

public bool LogSingleEvents { get; set; }

Property Value

bool

MachineName

Name of machine.

public string MachineName { get; set; }

Property Value

string

MaxLength

Maximum length of the log. If the length is exceeded, the log is trimmed to half, offset is set and the log continues.

public int MaxLength { get; set; }

Property Value

int

MultipleOperationEventCode

Explicit event log code used when LogSingleEvents is false (case of multiple logging).

public string MultipleOperationEventCode { get; set; }

Property Value

string

Offset

Offset of a partial log in a complete log

public int Offset { get; protected set; }

Property Value

int

UrlReferrer

Referrer url.

public string UrlReferrer { get; set; }

Property Value

string

UserAgent

Browser identification.

public string UserAgent { get; set; }

Property Value

string

Methods

Append(string, string)

Appends text to the log.

public static void Append(string text, string contextName = null)

Parameters

text string

Text to append

contextName string

Context name

AppendLine(string, string)

Appends text to the log.

public static void AppendLine(string text, string contextName = null)

Parameters

text string

Text to append

contextName string

Context name

AppendText(string, bool)

Appends the text.

public void AppendText(string text, bool newLine = true)

Parameters

text string

Text to append

newLine bool

Append as new line

Clear()

Clears the log

public void Clear()

Close()

Closes the log.

public void Close()

CloseCurrent()

Drops the current log context.

public static void CloseCurrent()

CloseLog(Guid)

Closes given log context.

public static void CloseLog(Guid logGuid)

Parameters

logGuid Guid

Log GUID

Dispose()

Disposes the object.

public void Dispose()

Dispose(bool)

Disposes object's log.

protected virtual void Dispose(bool disposing)

Parameters

disposing bool

Determines whether method was called from Dispose() or from the destructor

EnsureLog(Guid)

Ensures the log for given GUID.

public static LogContext EnsureLog(Guid logGuid)

Parameters

logGuid Guid

Log GUID

Returns

LogContext

LogEvent(string, string, string, string, int, string, DateTime)

Writes a new record to the event log.

public void LogEvent(string eventType, string source, string eventCode, string eventDescription, int userId, string userName, DateTime eventTime)

Parameters

eventType string

Type of the event. Please use predefined constants from EventType class.

source string

Source of the event (Content, Administration, etc.)

eventCode string

Event code (Security, Update, Delete, etc.)

eventDescription string

Detailed description of the event

userId int

ID of the user, who caused logged event

userName string

Name of the user, who caused logged event

eventTime DateTime

Date and time when the event occurs

LogEventToCurrent(string, string, string, string, int, string, DateTime)

Writes a new record to the event log using Current context.

public static void LogEventToCurrent(string eventType, string source, string eventCode, string eventDescription, int userId, string userName, DateTime eventTime)

Parameters

eventType string

Type of the event. Please use predefined constants from EventType class.

source string

Source of the event (Content, Administration, etc.)

eventCode string

Event code (Security, Update, Delete, etc.)

eventDescription string

Detailed description of the event

userId int

ID of the user, who caused logged event

userName string

Name of the user, who caused logged event

eventTime DateTime

Date and time when the event occurs

LogExists(Guid)

Returns true if the given log exists.

public static bool LogExists(Guid logGuid)

Parameters

logGuid Guid

Log GUID

Returns

bool

RaiseOnChanged()

Fires the onchanged event.

protected void RaiseOnChanged()

SetAllowedContexts(params string[])

Sets the list of the context names that the log context accepts. Use empty string for context which logs messages that do not provide context.

public void SetAllowedContexts(params string[] contextNames)

Parameters

contextNames string[]

Context names

Events

OnChanged

Fires when the log has changed.

public event EventHandler OnChanged

Event Type

EventHandler

TextAppended

Event which fires if some text is appended to the log

public event Action<string, bool> TextAppended

Event Type

Action<string, bool>