Class LogContext
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
-
objectLogContext
- 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
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
Event
Info object of type EventLogInfo.
public EventLogInfo Event { get; set; }
Property Value
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
stringText to append
contextName
stringContext name
AppendLine(string, string)
Appends text to the log.
public static void AppendLine(string text, string contextName = null)
Parameters
text
stringText to append
contextName
stringContext name
AppendText(string, bool)
Appends the text.
public void AppendText(string text, bool newLine = true)
Parameters
text
stringText to append
newLine
boolAppend 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
GuidLog GUID
Dispose()
Disposes the object.
public void Dispose()
Dispose(bool)
Disposes object's log.
protected virtual void Dispose(bool disposing)
Parameters
disposing
boolDetermines 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
GuidLog GUID
Returns
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
stringType of the event. Please use predefined constants from EventType class.
source
stringSource of the event (Content, Administration, etc.)
eventCode
stringEvent code (Security, Update, Delete, etc.)
eventDescription
stringDetailed description of the event
userId
intID of the user, who caused logged event
userName
stringName of the user, who caused logged event
eventTime
DateTimeDate 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
stringType of the event. Please use predefined constants from EventType class.
source
stringSource of the event (Content, Administration, etc.)
eventCode
stringEvent code (Security, Update, Delete, etc.)
eventDescription
stringDetailed description of the event
userId
intID of the user, who caused logged event
userName
stringName of the user, who caused logged event
eventTime
DateTimeDate and time when the event occurs
LogExists(Guid)
Returns true if the given log exists.
public static bool LogExists(Guid logGuid)
Parameters
logGuid
GuidLog 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>