Skip to content

Debug Library

Logger


Description

Provides static methods for logging messages and checking conditions (Asserting). The logging functions write messages in the Application's log and (if required) in the browser's console.

Methods

Write(Object)

Description

Writes the value of the object’s ToString() method.

Return Type : void

Static : Yes

Namespace : DebugLib.Logger

Parameters

Name Data Type Description
item Object The object to log.

Syntax

DebugLib.Logger.Write("Debugging!"); //Will write 'Debugging'

int number = 1;
DebugLib.Logger.Write(number); //Will write '1', as resulted from number.ToString()



WriteLine(Object)

Description

Writes the value of the object’s ToString() method followed by a line terminator.

Return Type : void

Static : Yes

Namespace : DebugLib.Logger

Parameters

Name Data Type Description
item Object The object to log.

Syntax

DebugLib.Logger.WriteLine("Debugging!"); //Will write 'Debugging\r\n'

int number = 1;
DebugLib.Logger.WriteLine(number); //Will write '1\r\n', as resulted from number.ToString()



WriteLine(Object, bool)

Description

Writes the value of the object’s ToString() method followed by a line terminator. If required, appends the logged item to the Browser's Console.

Return Type : void

Static : Yes

Namespace : DebugLib.Logger

Parameters

Name Data Type Description
item Object The object to log.
showInDebugConsole bool If true, log will be displayed in browser’s console.

Syntax

DebugLib.Logger.WriteLine("This line will be written only in the Log file", false);
DebugLib.Logger.WriteLine("This line will be written in the Log file and displayed in the browser's console", true);



WriteInfoLine(Object)

Description

Writes the value of the object’s ToString() method followed by a line terminator when the DEBUG level in the web config is INFO.

Return Type : void

Static : Yes

Namespace : DebugLib.Logger

Parameters

Name Data Type Description
item Object The object to log.

Syntax

DebugLib.Logger.WriteInfoLine("Successfully fetched Dataset")



WriteInfoLine(Object, bool)

Description

Writes the value of the object’s ToString() method followed by a line terminator when the DEBUG level in the web config is INFO. If required, writes the logged item in the Browser's Console.

Return Type : void

Static : Yes

Namespace : DebugLib.Logger

Parameters

Name Data Type Description
item Object The object to log.
showInDebugConsole bool If true, log will be displayed in browser’s console.

Syntax

DebugLib.Logger.WriteInfoLine("Successfully fetched Dataset", false);
DebugLib.Logger.WriteInfoLine("User logged in.", true);



WriteWarnLine(Object)

Description

Writes the value of the object’s ToString() method followed by a line terminator when the DEBUG level in the web config is WARN.

Return Type : void

Static : Yes

Namespace : DebugLib.Logger

Parameters

Name Data Type Description
item Object The object to log.

Syntax

DebugLib.Logger.WriteWarnLine("User did not select a Country. Setting the first one, by Default");



WriteWarnLine(Object, bool)

Description

Writes the value of the object’s ToString() method followed by a line terminator when the DEBUG level in the web config is WARN. If required, writes the logged item in the Browser's Console.

Return Type : void

Static : Yes

Namespace : DebugLib.Logger

Parameters

Name Data Type Description
item Object The object to log.
showInDebugConsole bool If true, log will be displayed in browser’s console.

Syntax

try {
    //Some code here
}
catch Exception x {
    DebugLib.Logger.WriteWarnLine("User did not select a Country. Setting the first one, by default", true); //Show a plain message in the browser's console
    DebugLib.Logger.WriteWarnLine("Exception:" + x.StackTrace, false); //Do not show your complete stacktrace, for security reasons
    //Silent exception
}



WriteErrorLine(Object)

Description

Writes the value of the object’s ToString() method followed by a line terminator when the DEBUG level in the web config is ERROR. If required, writes the logged item in the Browser's Console.

Return Type : void

Static : Yes

Namespace : DebugLib.Logger

Parameters

Name Data Type Description
item Object The object to log

Syntax

DebugLib.Logger.WriteErrorLine("Lost connection to the Database");



WriteErrorLine(Object, bool)

Description

Writes the value of the object’s ToString() method followed by a line terminator when the DEBUG level in the web config is ERROR. If required, writes the logged item in the Browser's Console.

Return Type : void

Static : Yes

Namespace : DebugLib.Logger

Parameters

Name Data Type Description
item Object The object to log
showInDebugConsole bool If true, log will be displayed in browser’s console

Syntax

try {
    //Some code here
}
catch Exception x {
    DebugLib.Logger.WriteErrorLine("Lost connection to the Database", true); //Show a plain message in the browser's console
    DebugLib.Logger.WriteErrorLine("Exception:" + x.StackTrace, false); //Do not show your complete stacktrace, for security reasons
    throw x;
}



Assert(bool, string)

Description

Evaluates a condition and, if it is false, displays a message

Return Type : void

Static : Yes

Namespace : DebugLib.Logger

Parameters

Name Data Type Description
condition bool The conditional expression to evaluate.
message string The message to display, if the condition is False.

Syntax

string letter = "a";
Debug.Assert(letter == "a", "Letter is not a");