Class Logger
Provides methods and events to support logging of messages to the user.
Namespace: ABB.Robotics.RobotStudio
Assembly: ABB.Robotics.RobotStudio.dll
Syntax
public static class Logger
Examples
Project.UndoContext.BeginUndoStep("Logger");
try
{
// Add two categories.
if (!Logger.CategoryCaptions.ContainsKey("MyKey"))
{
Logger.CategoryCaptions.Add("MyKey", "My Category");
Logger.CategoryCaptions.Add("AnotherKey", "Another Category");
}
// Add two messages with different category.
Logger.AddMessage(new LogMessage("This is just a test message!", "MyKey"));
Logger.AddMessage(new LogMessage("This is just a test message!", "AnotherKey"));
// How to create log messages with hyperlinks.
string path = @"C:\";
string textString = "Start text {{browse to file here}} more text {{google link here}} more text {{message box here}} end text";
// Add a message with three hyperlinks.
Logger.AddMessage(new LogMessage(textString, (index) =>
{
// If the user clicks a hyperlink this action will be called with the hyperlink index as argument. Index is zero based and is counted left to right.
switch (index)
{
// If the left-most hyperlink is clicked, index will be 0.
case 0:
Process.Start("explorer.exe", $"/select,\"{path}\"");
break;
// If second (from the left) hyperlink is clicked, index will be 1.
case 1:
Process.Start("http://google.com");
break;
// If third hyperlink is clicked, index will be 2.
case 2:
MessageBox.Show("Message box");
break;
default:
break;
}
}));
}
catch
{
Project.UndoContext.CancelUndoStep(CancelUndoStepType.Rollback);
throw;
}
finally
{
Project.UndoContext.EndUndoStep();
}
Fields
View SourceDefaultMessageActivatedHandler
Called when a message of the type "LogMessage" is activated
Declaration
public static Action<LogMessage> DefaultMessageActivatedHandler
Field Value
| Type | Description |
|---|---|
| Action<LogMessage> |
Properties
View SourceCategoryCaptions
Key-value pairs for translating category ids to (localized) texts.
Declaration
public static Dictionary<string, string> CategoryCaptions { get; }
Property Value
| Type | Description |
|---|---|
| Dictionary<string, string> |
Methods
View SourceActivateMessage(LogMessage)
Fires the LogMessageActivated event.
Declaration
[Obsolete("Replaced by ActivateMessage(object, LogMessage)")]
public static void ActivateMessage(LogMessage msg)
Parameters
| Type | Name | Description |
|---|---|---|
| LogMessage | msg |
ActivateMessage(object, LogMessage)
Fires the LogMessageActivated and MessageActivated events and shows more details if the Handled is not True and the LogMessage is of base class type.
Declaration
public static void ActivateMessage(object sender, LogMessage message)
Parameters
| Type | Name | Description |
|---|---|---|
| object | sender | |
| LogMessage | message |
AddMessage(LogMessage)
Adds a log message to the logger.
Declaration
public static void AddMessage(LogMessage msg)
Parameters
| Type | Name | Description |
|---|---|---|
| LogMessage | msg | The LogMessage to add. |
Remarks
This method is thread safe.
AddMessage(LogMessage, bool)
Adds a log message to the logger.
Declaration
public static void AddMessage(LogMessage msg, bool bringToFront)
Parameters
| Type | Name | Description |
|---|---|---|
| LogMessage | msg | The LogMessage to add. |
| bool | bringToFront | Indicates whether the output window should be brought to the foreground then the message is added. |
Remarks
This method is thread safe.
AddMessage(string)
Adds an information log message to the logger.
Declaration
public static void AddMessage(string message)
Parameters
| Type | Name | Description |
|---|---|---|
| string | message | The message to add. |
Remarks
This method is thread safe.
AddMessage(string, LogMessageSeverity)
Adds a log message to the logger.
Declaration
public static void AddMessage(string message, LogMessageSeverity severity)
Parameters
| Type | Name | Description |
|---|---|---|
| string | message | The message to add. |
| LogMessageSeverity | severity | The severity of the message. |
Remarks
This method is thread safe.
AddMessage(string, bool)
Adds an information log message to the logger.
Declaration
public static void AddMessage(string message, bool bringToFront)
Parameters
| Type | Name | Description |
|---|---|---|
| string | message | The message to add. |
| bool | bringToFront | Indicates whether the output window should be brought to the foreground then the message is added. |
Remarks
This method is thread safe.
Clear()
Clears the logger. All messages are removed.
Declaration
public static void Clear()
Remarks
This method is thread safe.
Clear(bool)
Clears the logger. All messages are removed.
Declaration
public static void Clear(bool removeFromOutput)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | removeFromOutput | Indicates if the messages should be removed from the Output view. |
Remarks
This method is thread safe.
Clear(string)
Removes all log messages with the specified category.
Declaration
public static void Clear(string category)
Parameters
| Type | Name | Description |
|---|---|---|
| string | category |
Remarks
This method is thread safe.
Clear(string, bool)
Removes all log messages with the specified category.
Declaration
public static void Clear(string category, bool removeFromOutput)
Parameters
| Type | Name | Description |
|---|---|---|
| string | category | |
| bool | removeFromOutput | Indicates if the messages should be removed from the Output view. |
Remarks
This method is thread safe.
GetMessages()
Returns an all log messages in the logger.
Declaration
public static LogMessage[] GetMessages()
Returns
| Type | Description |
|---|---|
| LogMessage[] |
Remarks
This method is thread safe.
GetMessages(string)
Returns all log messages with the specified category.
Declaration
public static LogMessage[] GetMessages(string category)
Parameters
| Type | Name | Description |
|---|---|---|
| string | category |
Returns
| Type | Description |
|---|---|
| LogMessage[] |
Remarks
This method is thread safe.
RemoveMessage(LogMessage)
Removes a log message from the logger.
Declaration
public static void RemoveMessage(LogMessage msg)
Parameters
| Type | Name | Description |
|---|---|---|
| LogMessage | msg | The LogMessage to remove. |
Remarks
This method is thread safe.
RemoveMessage(LogMessage, bool)
Removes a log message from the logger.
Declaration
public static void RemoveMessage(LogMessage msg, bool removeFromOutput)
Parameters
| Type | Name | Description |
|---|---|---|
| LogMessage | msg | The LogMessage to remove. |
| bool | removeFromOutput | Indicates if the message should be removed from the Output view. |
Remarks
This method is thread safe.
Events
View SourceLogMessageActivated
Declaration
[Obsolete("Replaced by MessageActivated")]
public static event EventHandler LogMessageActivated
Event Type
| Type | Description |
|---|---|
| EventHandler |
LogMessageAdded
Raised when a message is added.
Declaration
public static event LogMessageAddedEventHandler LogMessageAdded
Event Type
| Type | Description |
|---|---|
| LogMessageAddedEventHandler |
LogMessageRemoved
Raised when a message is removed.
Declaration
public static event LogMessageRemovedEventHandler LogMessageRemoved
Event Type
| Type | Description |
|---|---|
| LogMessageRemovedEventHandler |
MessageActivated
Raised when a message is activated, e.g. double-clicked in the GUI.
Declaration
public static event LogMessageActivatedEventHandler MessageActivated
Event Type
| Type | Description |
|---|---|
| LogMessageActivatedEventHandler |