Log Message() Method

(SBM On-Premise only) Writes a message to the log using the level provided.

Function Signature

 Message( int level, value )

Message( int level, string format, arg0-4 )

Parameters

Parameter Type Description

level

int

Corresponds to values from LogLevelConstants.

value

Variant

Value will be converted to a string and written to the log.

format

string

A format string with entries like {0} that correspond to arg0 etc. See notes below.

arg (up to 5)

Variant

A value that is formatted into the output text using the format parameter.

Return

Type Description

None

Technical Details

SBM ModScript version: 11.3.

Example

//Basic example of working with the Log class
var filePath = "Script.log";
//Creates a Log Object
var myLog = Log();
//Opens the Log Object
var isOpened = myLog.Open( filePath );
myLog.Message(LogLevelConstants.NONE, "Is log opened " + isOpened);
//Starts a new Log file when MaxSize is reached
var backUpFileSet = myLog.SetBackUpLogFile(true);
//Sets the number of bytes the log file should grow to before it is truncated
var maxSize = myLog.SetMaxSize(10485760);
//Adds timestamps to the entries
var wantTimeStamp = myLog.SetWantTimeStamp(true);
//Returns the current logging level
myLog.Message(LogLevelConstants.NONE, "Log reporting level: " + myLog.GetReportingLevel());
//Sets the log reporting level to Minimal
reportLevel = myLog.SetReportingLevel(LogLevelConstants.MINIMAL);
myLog.Message(myLog.NONE(), "Message level NONE" );
myLog.Message(LogLevelConstants.MINIMAL,"Message level MINIMAL" );
myLog.Message(LogLevelConstants.VERBOSE(), "Message level VERBOSE" );
//Logs the message with frmt (format string)
myLog.Message(LogLevelConstants.AVERAGE, 
  "Testing the {0} {1} to check that '{0}' {1}s to {0}. {2}, {3}, {4}",
  "STRING", "FORMAT", 2, 3, 4);
//Closes the Log Object
myLog.Close();

Notes

If the log is set to a lower level than the level passed in, this message will be ignored and not written to the log. See Log SetReportingLevel() Method.

The "format" parameter is a format string with places for up to five values in it. Those places are encoded in the string in {0} format, where the number is the zero-based index of the parameter to be placed in that location. Indexes can be repeated in the format string if that variable should be placed into the string more than one time. Literal "{" must be escaped by single ticks, literal single ticks must be escaped by single ticks.

Related Topics

Log