Show / Hide Table of Contents

Class Logger

Provides methods and events to support logging of messages to the user.

Inheritance
object
Logger
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 Source

DefaultMessageActivatedHandler

Called when a message of the type "LogMessage" is activated

Declaration
public static Action<LogMessage> DefaultMessageActivatedHandler
Field Value
Type Description
Action<LogMessage>

Properties

View Source

CategoryCaptions

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 Source

ActivateMessage(LogMessage)

Fires the LogMessageActivated event.

Declaration
[Obsolete("Replaced by ActivateMessage(object, LogMessage)")]
public static void ActivateMessage(LogMessage msg)
Parameters
Type Name Description
LogMessage msg
View Source

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
View Source

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.

View Source

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.

View Source

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.

View Source

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.

View Source

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.

View Source

Clear()

Clears the logger. All messages are removed.

Declaration
public static void Clear()
Remarks

This method is thread safe.

View Source

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.

View Source

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.

View Source

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.

View Source

GetMessages()

Returns an all log messages in the logger.

Declaration
public static LogMessage[] GetMessages()
Returns
Type Description
LogMessage[]
Remarks

This method is thread safe.

View Source

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.

View Source

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.

View Source

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 Source

LogMessageActivated

Declaration
[Obsolete("Replaced by MessageActivated")]
public static event EventHandler LogMessageActivated
Event Type
Type Description
EventHandler
View Source

LogMessageAdded

Raised when a message is added.

Declaration
public static event LogMessageAddedEventHandler LogMessageAdded
Event Type
Type Description
LogMessageAddedEventHandler
View Source

LogMessageRemoved

Raised when a message is removed.

Declaration
public static event LogMessageRemovedEventHandler LogMessageRemoved
Event Type
Type Description
LogMessageRemovedEventHandler
View Source

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
  • View Source
In this article
Back to top Copyright © 2025 ABB