Show / Hide Table of Contents

Class Log

Static class for application logging and tracing. This class is meant to be very fast, stable, resilient and memory efficient.

Inheritance
System.Object
Log
Namespace: Cobasoft
Assembly: Cobasoft.Log.dll
Syntax
public static class Log

Fields

ScopeCodes

Scope code characters. Scopes determine, what is written to the Log. For example, Log.Data() is only written if the 'D' flag is on. Scopes are specified as strings in configuration, but are kept internally as bit flags within an integer value. If scopes are turned off, this also prevents argument formatting for related methods, so it speeds up logging.

Declaration
public static readonly string ScopeCodes
Field Value
Type Description
System.String

SCOPECODES

Scope code strings. Meant to be indexed by Log.Type, like SCOPECODES[ (int) Exception ].

Declaration
public static readonly string[] SCOPECODES
Field Value
Type Description
System.String[]

TimingBegin

Declaration
public static readonly char TimingBegin
Field Value
Type Description
System.Char

TimingFinal

Declaration
public static readonly char TimingFinal
Field Value
Type Description
System.Char

TimingSplit

Declaration
public static readonly char TimingSplit
Field Value
Type Description
System.Char

Properties

AppBase

Try to get DomainBase, but if that is null, return CodeBase.

Declaration
public static string AppBase { get; }
Property Value
Type Description
System.String

AssemblyLocation

Get the assembly location path, without filename. For ASP.NET applications, this is in AppData...Temporary ASP.NET Files.

Declaration
public static string AssemblyLocation { get; }
Property Value
Type Description
System.String

CallerScope

Get all set the caller scope value. This is a bit flag, with one bit for each value in ScopeCodes.

Declaration
public static uint CallerScope { get; set; }
Property Value
Type Description
System.UInt32

CanData

Check if the current trace settings allow output of data traces.

Declaration
public static bool CanData { get; }
Property Value
Type Description
System.Boolean

CanEntry

Check if the current trace settings allow output of entry traces.

Declaration
public static bool CanEntry { get; }
Property Value
Type Description
System.Boolean

CanError

Check if the current trace settings allow output of errors traces.

Declaration
public static bool CanError { get; }
Property Value
Type Description
System.Boolean

CanException

Check if the current trace settings allow output of exceptions.

Declaration
public static bool CanException { get; }
Property Value
Type Description
System.Boolean

CanExit

Check if the current trace settings allow output of exit traces.

Declaration
public static bool CanExit { get; }
Property Value
Type Description
System.Boolean

CanInformation

Check if the current trace settings allow output of information traces.

Declaration
public static bool CanInformation { get; }
Property Value
Type Description
System.Boolean

CanMemory

Check if the current trace settings allow output of memory traces.

Declaration
public static bool CanMemory { get; }
Property Value
Type Description
System.Boolean

CanShowMessage

Check if the current trace settings allow message box dialogs. (Currently, message dialogs are not supported.)

Declaration
public static bool CanShowMessage { get; }
Property Value
Type Description
System.Boolean

CanTime

Check if the current trace settings allow message timing traces.

Declaration
public static bool CanTime { get; }
Property Value
Type Description
System.Boolean

CanVerbose

Check if the current trace settings allow output of verbose traces.

Declaration
public static bool CanVerbose { get; }
Property Value
Type Description
System.Boolean

CanWarning

Check if the current trace settings allow output of warning traces.

Declaration
public static bool CanWarning { get; }
Property Value
Type Description
System.Boolean

CodeBase

Get Assembly.GetEntryAssembly().Location, without filename. For ASP.NET applications, this is null.

Declaration
public static string CodeBase { get; }
Property Value
Type Description
System.String

CurrentDirectory

Get the current directory at the time when Cobasoft.Log was initialized.

Declaration
public static string CurrentDirectory { get; }
Property Value
Type Description
System.String

DomainBase

Get AppDomain.CurrentDomain.RelativeSearchPath. For desktop applications, this is null.

Declaration
public static string DomainBase { get; }
Property Value
Type Description
System.String

FileAge

Get or set the maximum log file age (in hours). Older log files will be deleted automatically.

Declaration
public static long FileAge { get; set; }
Property Value
Type Description
System.Int64

FilePath

Get or set the current log file path. If it is modified, the old log file is closed and then reopened.

Declaration
public static string FilePath { get; set; }
Property Value
Type Description
System.String

FileSize

Get or set the maximum file size. A new log file will be opened, when this size is exceeded.

Declaration
public static long FileSize { get; set; }
Property Value
Type Description
System.Int64

IsBreak

Gets the LogBreak configuration value.

Declaration
public static bool IsBreak { get; }
Property Value
Type Description
System.Boolean

IsDebug

Indicates if the DEBUG preprocessor flag is turned on.

Declaration
public static bool IsDebug { get; }
Property Value
Type Description
System.Boolean

IsFlush

Get or set the FlushOn flag. If this is turned on, every line is immediately written to the log file. That makes logging much slower, but allows to write trace before program crashes.

Declaration
public static bool IsFlush { get; set; }
Property Value
Type Description
System.Boolean

IsHalt

Get or set the DoHalt flag. If this is turned on, every warning, error or exception breaks into the debugger, if a debugger is attached. To turn this off during runtime, while being breaked in a debugger, you can run one of the following statements in the Immediate window: Log.NoHalt() or Log.IsHalt = false;

Declaration
public static bool IsHalt { get; set; }
Property Value
Type Description
System.Boolean

Scope

Get or set the scope value. This is a bit flag, with one bit for each value in ScopeCodes.

Declaration
public static uint Scope { get; set; }
Property Value
Type Description
System.UInt32

TickCount

Get TickCount as unsigned integer.

Declaration
public static uint TickCount { get; }
Property Value
Type Description
System.UInt32

ToConsole

Get or set ToConsole flag. If this is turned off, no System.Console trace is written.

Declaration
public static bool ToConsole { get; set; }
Property Value
Type Description
System.Boolean

ToFile

Get or set the ToFile flag. If this is turned off, no log file is written.

Declaration
public static bool ToFile { get; set; }
Property Value
Type Description
System.Boolean

ToListener

Get or set the ToListener flag. If this is turned off, no custom listener is being called.

Declaration
public static bool ToListener { get; set; }
Property Value
Type Description
System.Boolean

ToTrace

Get or set the ToTrace flag. If this is turned off, no System.Diagnostics.Trace is written.

Declaration
public static bool ToTrace { get; set; }
Property Value
Type Description
System.Boolean

Methods

Assert(Boolean, String, String)

If the expression is false, show class name and error message.

Declaration
public static bool Assert(bool expression, string classname, string message)
Parameters
Type Name Description
System.Boolean expression
System.String classname
System.String message
Returns
Type Description
System.Boolean

Assert(Boolean, String, String, String, Int32)

If the expression is false, show error message and caller information.

Declaration
public static bool Assert(bool expression, string message = null, string member = null, string file = null, int line = 0)
Parameters
Type Name Description
System.Boolean expression
System.String message
System.String member
System.String file
System.Int32 line
Returns
Type Description
System.Boolean

AssertV(Boolean, Object[])

If the expression is false, show formatted name=value information.

Declaration
public static bool AssertV(bool expression, params object[] values)
Parameters
Type Name Description
System.Boolean expression
System.Object[] values
Returns
Type Description
System.Boolean

Attach(Log.ListenerA)

Attach ListenerA.

Declaration
public static void Attach(Log.ListenerA listener)
Parameters
Type Name Description
Log.ListenerA listener

Attach2(Log.ListenerB)

Attach ListenerB.

Declaration
public static void Attach2(Log.ListenerB listener)
Parameters
Type Name Description
Log.ListenerB listener

CallerFile(String)

Declaration
public static string CallerFile(string value = null)
Parameters
Type Name Description
System.String value
Returns
Type Description
System.String

CallerLine(Int32)

Declaration
public static string CallerLine(int value = 0)
Parameters
Type Name Description
System.Int32 value
Returns
Type Description
System.String

CallerMember(String)

Declaration
[Obsolete]
public static string CallerMember(string value = null)
Parameters
Type Name Description
System.String value
Returns
Type Description
System.String

Can(Log.Type)

Check if the current trace settings allow output of the given type

Declaration
public static bool Can(Log.Type type)
Parameters
Type Name Description
Log.Type type
Returns
Type Description
System.Boolean

CanCaller(Log.Type)

Check if the current trace settings allow caller information for the given type

Declaration
public static bool CanCaller(Log.Type type)
Parameters
Type Name Description
Log.Type type
Returns
Type Description
System.Boolean

CCM(Object, String)

Declaration
public static string CCM(object o, string value = null)
Parameters
Type Name Description
System.Object o
System.String value
Returns
Type Description
System.String

Close()

Close the file writer. This will stop tracing to file, until Open is being called. This message should normally not be called by applications.

Declaration
public static void Close()

CM(String)

Declaration
public static string CM(string value = null)
Parameters
Type Name Description
System.String value
Returns
Type Description
System.String

Data(String, String, String, Int32)

Show data message and caller information.

Declaration
public static void Data(string message, string member = null, string file = null, int line = 0)
Parameters
Type Name Description
System.String message
System.String member
System.String file
System.Int32 line

DataV(String, Object[])

Show data message and formatted name=value information.

Declaration
public static void DataV(string message, params object[] values)
Parameters
Type Name Description
System.String message
System.Object[] values

DateHeader(DateTime)

Create our date header: 2018-10-24 11:51:26.363

Declaration
public static string DateHeader(DateTime dt)
Parameters
Type Name Description
System.DateTime dt
Returns
Type Description
System.String

Debug(String, String, String, Int32)

Declaration
[Conditional("DEBUG")]
public static void Debug(string message, string member = null, string file = null, int line = 0)
Parameters
Type Name Description
System.String message
System.String member
System.String file
System.Int32 line

DebugAssert(Boolean, String, String, Int32)

DebugBreak when expression is false.

Declaration
public static void DebugAssert(bool expression, string member = null, string file = null, int line = 0)
Parameters
Type Name Description
System.Boolean expression
System.String member
System.String file
System.Int32 line

DebugBreak(String, String, Int32)

Break into debugger, only if one is attached.

Declaration
public static void DebugBreak(string member = null, string file = null, int line = 0)
Parameters
Type Name Description
System.String member
System.String file
System.Int32 line

DebugV(String, Object[])

Show data message and formatted name=value information, only in DEBUG mode.

Declaration
[Conditional("DEBUG")]
public static void DebugV(string message, params object[] values)
Parameters
Type Name Description
System.String message
System.Object[] values

Deny(Boolean, String, String)

If the expression is true, show class name and error message.

Declaration
public static bool Deny(bool expression, string classname, string message)
Parameters
Type Name Description
System.Boolean expression
System.String classname
System.String message
Returns
Type Description
System.Boolean

Deny(Boolean, String, String, String, Int32)

If the expression is true, show error message and caller information.

Declaration
public static bool Deny(bool expression, string message = null, string member = null, string file = null, int line = 0)
Parameters
Type Name Description
System.Boolean expression
System.String message
System.String member
System.String file
System.Int32 line
Returns
Type Description
System.Boolean

DenyV(Boolean, Object[])

If the expression is true, show formatted name=value information.

Declaration
public static bool DenyV(bool expression, params object[] values)
Parameters
Type Name Description
System.Boolean expression
System.Object[] values
Returns
Type Description
System.Boolean

Detach()

Detach ListenerA.

Declaration
public static void Detach()

Detach2()

Detach ListenerB.

Declaration
public static void Detach2()

Enable(Boolean, Boolean, Boolean, Boolean)

Enable or disable output options.

Declaration
public static void Enable(bool file = true, bool console = true, bool trace = true, bool listener = true)
Parameters
Type Name Description
System.Boolean file
System.Boolean console
System.Boolean trace
System.Boolean listener

Entry(String, String, Int32)

Show function entry message and caller information.

Declaration
public static void Entry(string member = null, string file = null, int line = 0)
Parameters
Type Name Description
System.String member
System.String file
System.Int32 line

EntryV(String, Object[])

Show function entry message and formatted name=value information.

Declaration
public static void EntryV(string message, params object[] values)
Parameters
Type Name Description
System.String message
System.Object[] values

Error(String, String, String, Int32)

Show error message and caller information.

Declaration
public static void Error(string message, string member = null, string file = null, int line = 0)
Parameters
Type Name Description
System.String message
System.String member
System.String file
System.Int32 line

ErrorV(String, Object[])

Show error message and formatted name=value information.

Declaration
public static void ErrorV(string message, params object[] values)
Parameters
Type Name Description
System.String message
System.Object[] values

Exception(Exception, String, String, Int32)

Write the exception to the log stream.

Declaration
public static void Exception(Exception ex, string member = null, string file = null, int line = 0)
Parameters
Type Name Description
System.Exception ex
System.String member
System.String file
System.Int32 line

Exception(String, Exception, String, String, Int32)

Write the message and the exception to the log stream.

Declaration
public static void Exception(string message, Exception ex, string member = null, string file = null, int line = 0)
Parameters
Type Name Description
System.String message
System.Exception ex
System.String member
System.String file
System.Int32 line

ExceptionV(String, Exception, Object[])

Show exception information message and formatted name=value information.

Declaration
public static void ExceptionV(string message, Exception ex, params object[] values)
Parameters
Type Name Description
System.String message
System.Exception ex
System.Object[] values

ExceptionV(String, String, Exception, Object[])

Show exception information message and formatted name=value information.

Declaration
public static void ExceptionV(string classname, string message, Exception ex, params object[] values)
Parameters
Type Name Description
System.String classname
System.String message
System.Exception ex
System.Object[] values

Exit(String, String, Int32)

Show function exit message and caller information.

Declaration
public static void Exit(string member = null, string file = null, int line = 0)
Parameters
Type Name Description
System.String member
System.String file
System.Int32 line

ExitV(String, Object[])

Show function exit message and formatted name=value information.

Declaration
public static void ExitV(string message, params object[] values)
Parameters
Type Name Description
System.String message
System.Object[] values

Fail(String, String, String, Int32)

Trigger an assertion. Show message and caller information.

Declaration
public static bool Fail(string message = null, string member = null, string file = null, int line = 0)
Parameters
Type Name Description
System.String message
System.String member
System.String file
System.Int32 line
Returns
Type Description
System.Boolean

FailV(String, Object[])

Trigger an assertion. Show message and formatted name=value information.

Declaration
public static bool FailV(string message = null, params object[] values)
Parameters
Type Name Description
System.String message
System.Object[] values
Returns
Type Description
System.Boolean

Flush()

Flush the output buffer to file.

Declaration
public static void Flush()

Format(String, Object[])

Build a name=value list from the arguments.

Declaration
public static string Format(string message, params object[] values)
Parameters
Type Name Description
System.String message
System.Object[] values
Returns
Type Description
System.String

FormatArray(Object)

Utility function for formatting any enumerable.

Declaration
public static string FormatArray(object v)
Parameters
Type Name Description
System.Object v
Returns
Type Description
System.String

GetBit(UInt32, Int32)

Declaration
public static bool GetBit(uint value, int pos)
Parameters
Type Name Description
System.UInt32 value
System.Int32 pos
Returns
Type Description
System.Boolean

GetCode(Log.Type)

Convert Type into a scope code characters.

Declaration
public static char GetCode(Log.Type type)
Parameters
Type Name Description
Log.Type type
Returns
Type Description
System.Char

GetScope(String)

Get scope flags from a string like "XEWI".

Declaration
public static uint GetScope(string scope)
Parameters
Type Name Description
System.String scope
Returns
Type Description
System.UInt32

GetScope(UInt32)

Get scope string from scope flags.

Declaration
public static string GetScope(uint flags)
Parameters
Type Name Description
System.UInt32 flags
Returns
Type Description
System.String

GetType(Char)

Get Type from a character code. Might return -1, if the code is not known.

Declaration
public static int GetType(char code)
Parameters
Type Name Description
System.Char code
Returns
Type Description
System.Int32

Header()

Write header trace.

Declaration
public static void Header()

IndexOfII(String, String)

Try to find position of b within a, invariant culture, ignore case. Return -1 if not found.

Declaration
public static int IndexOfII(this string a, string b)
Parameters
Type Name Description
System.String a
System.String b
Returns
Type Description
System.Int32

Info(String, String, String, Int32)

Show informational message and caller information.

Declaration
public static void Info(string message, string member = null, string file = null, int line = 0)
Parameters
Type Name Description
System.String message
System.String member
System.String file
System.Int32 line

InfoV(String, Object[])

Show informational message and formatted name=value information.

Declaration
public static void InfoV(string message, params object[] values)
Parameters
Type Name Description
System.String message
System.Object[] values

Init()

Initialize

Declaration
public static void Init()

Literal(Log.Type, String)

Write literal message to all active targets (File, System.Diagnostics.Trace, System.Console), but not to the custom listeners.

Declaration
public static void Literal(Log.Type type, string message)
Parameters
Type Name Description
Log.Type type
System.String message

MemberName(Object, String)

Get a formatted member name in the form 'ClassName.MethodName'.

Declaration
public static string MemberName(object o, string value = null)
Parameters
Type Name Description
System.Object o
System.String value
Returns
Type Description
System.String

Memory(String)

Write memory trace. Format: " M 0041451520 | 0001150976 | This is the comment".

Declaration
public static void Memory(string message)
Parameters
Type Name Description
System.String message

MinScope()

Set minimum scope ("XE"). Meant to be used during interactive debugging.

Declaration
public static void MinScope()

NoHalt()

Prevent automatic breaking into debugger. This is meant to be used during interactive debugging, to turn off breaks because of exceptions or other errors.

Declaration
public static void NoHalt()

NOP()

Just do nothing. Can be used for setting breakpoints or do-nothing callbacks.

Declaration
public static void NOP()

NotImplemented(String, String, Int32)

Write not-implemented message with caller information.

Declaration
public static void NotImplemented(string member = null, string file = null, int line = 0)
Parameters
Type Name Description
System.String member
System.String file
System.Int32 line

NotTested(String, String, Int32)

Write not-tested message with caller information.

Declaration
public static void NotTested(string member = null, string file = null, int line = 0)
Parameters
Type Name Description
System.String member
System.String file
System.Int32 line

Pad(Int32, Int32, Char)

Format a value with a fixed number of digits (between 1 and 9).

Declaration
public static string Pad(int v, int digits, char separator = '\0')
Parameters
Type Name Description
System.Int32 v
System.Int32 digits
System.Char separator
Returns
Type Description
System.String

Pad(Int64, Int32, Char)

Format a value with a fixed number of digits.

Declaration
public static string Pad(long v, int digits, char separator = '\0')
Parameters
Type Name Description
System.Int64 v
System.Int32 digits
System.Char separator
Returns
Type Description
System.String

Pad(UInt32, Int32, Char)

Format a value with a fixed number of digits (between 1 and 9).

Declaration
public static string Pad(uint v, int digits, char separator = '\0')
Parameters
Type Name Description
System.UInt32 v
System.Int32 digits
System.Char separator
Returns
Type Description
System.String

Pad(UInt64, Int32, Char)

Format a value with a fixed number of digits (between 1 and 9).

Declaration
public static string Pad(ulong v, int digits, char separator = '\0')
Parameters
Type Name Description
System.UInt64 v
System.Int32 digits
System.Char separator
Returns
Type Description
System.String

RemoveCharacters(String, Char[])

Remove characters from string.

Declaration
public static string RemoveCharacters(string v, params char[] unwanted)
Parameters
Type Name Description
System.String v
System.Char[] unwanted
Returns
Type Description
System.String

ResetCallerScope()

Reset caller scope.

Declaration
public static void ResetCallerScope()

ResetScope()

Reset scope.

Declaration
public static void ResetScope()

SetCallerScope(String)

Use a string like "XEWI" to set _CallerScope. Caller information is only written to output, if the current Type is matching the Scope.

Declaration
public static ulong SetCallerScope(string scope)
Parameters
Type Name Description
System.String scope
Returns
Type Description
System.UInt64

SetScope(String)

Use a string like "XEWI" to set _Scope. Only traces, where Type is matching Scope are written to output.

Declaration
public static ulong SetScope(string scope)
Parameters
Type Name Description
System.String scope
Returns
Type Description
System.UInt64

SmallException(Exception, String, String, Int32)

Write exception and caller information to Log as verbose message.

Declaration
public static void SmallException(Exception ex, string member = null, string file = null, int line = 0)
Parameters
Type Name Description
System.Exception ex
System.String member
System.String file
System.Int32 line

SmallExceptionV(String, Exception, Object[])

Declaration
public static void SmallExceptionV(string message, Exception ex, params object[] values)
Parameters
Type Name Description
System.String message
System.Exception ex
System.Object[] values

SplitTime(String, String)

Write delta time trace. Time is not reset. Format: " T key . 0000012345 message".

Declaration
public static void SplitTime(string key, string message)
Parameters
Type Name Description
System.String key
System.String message

StartTime(String, Boolean)

For programmatic time measurements: Store start time for a key.

Declaration
public static void StartTime(string key, bool show = false)
Parameters
Type Name Description
System.String key
System.Boolean show

StopTime(String, String)

Write delta time trace. Time is reset! Format: " T key ! 0000012345 message".

Declaration
public static void StopTime(string key, string message)
Parameters
Type Name Description
System.String key
System.String message

ThreadName()

Get Thread name (4 chars).

Declaration
public static string ThreadName()
Returns
Type Description
System.String

Time(UInt32, String, String, String, Int32)

Write timing and caller information to the log stream.

Declaration
public static void Time(uint delta, string message, string member = null, string file = null, int line = 0)
Parameters
Type Name Description
System.UInt32 delta
System.String message
System.String member
System.String file
System.Int32 line

TimeV(UInt32, String, Object[])

Show timing information, message and formatted name=value information.

Declaration
public static void TimeV(uint delta, string message, params object[] values)
Parameters
Type Name Description
System.UInt32 delta
System.String message
System.Object[] values

Trim(String, Int32, Boolean)

Trim string argument to given length, optionally remove linebreaks.

Declaration
public static string Trim(string value, int length, bool cleanCrLf)
Parameters
Type Name Description
System.String value
System.Int32 length
System.Boolean cleanCrLf
Returns
Type Description
System.String

TypeName(Object)

Get the class or type name of this object.

Declaration
public static string TypeName(object o)
Parameters
Type Name Description
System.Object o
Returns
Type Description
System.String

VarVal(Object[])

Build a name=value list from the arguments.

Declaration
public static string VarVal(params object[] values)
Parameters
Type Name Description
System.Object[] values
Returns
Type Description
System.String

Verbose(String, String, String, Int32)

Show verbose message and caller information.

Declaration
public static void Verbose(string message, string member = null, string file = null, int line = 0)
Parameters
Type Name Description
System.String message
System.String member
System.String file
System.Int32 line

VerboseV(String, Object[])

Show verbose message and formatted name=value information.

Declaration
public static void VerboseV(string message, params object[] values)
Parameters
Type Name Description
System.String message
System.Object[] values

Warning(String, String, String, Int32)

Show warning message and caller information.

Declaration
public static void Warning(string message, string member = null, string file = null, int line = 0)
Parameters
Type Name Description
System.String message
System.String member
System.String file
System.Int32 line

WarningV(String, Object[])

Show morning message and formatted name=value information.

Declaration
public static void WarningV(string message, params object[] values)
Parameters
Type Name Description
System.String message
System.Object[] values

Write(Log.Type, String)

Write message to all outputs, if it matches the Scope filter.

Declaration
public static void Write(Log.Type type, string message)
Parameters
Type Name Description
Log.Type type
System.String message

Write(Log.Type, String, String, String, Int32)

Write message and caller information to log stream, if Type matches the Scope filter. And caller information is only written if Type matches the CallerScope.

Declaration
public static void Write(Log.Type type, string message, string member = null, string file = null, int line = 0)
Parameters
Type Name Description
Log.Type type
System.String message
System.String member
System.String file
System.Int32 line

WriteTime(Char, String, String, UInt32)

Write timing information

Declaration
public static void WriteTime(char indicator, string key, string message, uint delta)
Parameters
Type Name Description
System.Char indicator
System.String key
System.String message
System.UInt32 delta

WriteV(Log.Type, String, Object[])

Write message and name/value pairs to all outputs, if Type matches the Scope filter.

Declaration
public static void WriteV(Log.Type type, string message, params object[] values)
Parameters
Type Name Description
Log.Type type
System.String message
System.Object[] values
In This Article
Back to top Generated by DocFX