Skip to content

Work with Lightrun Dynamic Logs in the Visual Studio IDE

Important

The Lightrun extension for Visual Studio, referred to hereafter as the "Lightrun plugin", is in public beta.

Prerequisites

To use the plugin, make sure you have:

  1. Attached an agent to your application.
  2. Installed the plugin in your local Visual Studio instance.
  3. Authenticated the Visual Studio plugin against your Lightrun account.
  4. Verfified that the source code file for your running application is opened in Visual Studio.

From the Lightrun plugin for Visual Studio, you can:

Add Lightrun logs to your application in the IDE

To add dynamic logs to your code, you must open the Insert a Log dialog and enter your preferred log parameters.

  1. Access the Insert a Log dialog.

    You can access the Insert a Log dialog from the Lightrun plugin or directly in the code editor within the IDE.

    • From the Lightrun plugin

      1. Open the Lightrun sidebar in your Visual Studio IDE.
      2. Click the Plus icon at the top of the plugin, or go to the Agents or Tags tab and select an agent or tag.
      3. Click the Add Action.
      4. Select Log in the menu that appears.

        Lightrun context menu --half

    • Directly in the Code Editor

      1. Go to the line in your application source code where you'd like to insert the log. Make sure to use the source code version currently deployed to your remote app (where the agent is attached).
      2. Right-click to open the Visual Studio context menu.
      3. From the Visual Studio context menu, click Lightrun.
        The Visual Studio Command Palette opens with a list of Lightrun plugin options.

        Lightrun context menu --half

      4. From the Command Palette, select Add Log.

        Add log --half

  2. Configure the log parameters.

    The Insert a Log dialog should appear similar to the following image.

    Insert a log dialog --half

  3. Complete the fields in the Insert a Log dialog, as follows:

    Fields Description
    Source From the available options in the dropdown list, bind the action to a specific agent, tag, or custom source.
    Click the Custom Source icon --icon icon to create a new custom source.
    Filename & Line The source code file into which you're inserting the action. The default path is to the source code file from which you're currently working.
    Log message The actual log string. Use expressions such as My variable is {var}, including method invocations such as: Method value: {myMethod() + 5}.
    Log level Select an appropriate log level: INFO, ERROR, DEBUG, WARN.
    Once configured, logs can also be filtered by the LOG LEVEL attribute in the Lightrun console.
    Condition The condition of an if statement, used to limit the execution of the action.
    For example, The condition myVar % 7 == 0 limits the action (log, snapshot, metric) output so that it only prints for variables that are divisible by 7.
    Lifetime The time after which the action ceases to track code behavior and is automatically disabled; default = 1 hour.
    Target Select your preferred action output taget. You can pick either:
    - Stdout: Logs are routed only to your application's standard output.
    - Plugin: Logs appear in the Lightrun Console, the Lightrun Management Portal, and configured integrations or both options at once.
  4. Click Create to insert the dynamic log into your code.

Manage Lightrun logs

Access your log in the code

  1. In the Visual Studio editor, a Log icon --icon icon will appear next to the selected code line.
  2. A new log action will appear under the selected source (agent or tag) in the Lightrun sidebar. Log entry

  3. You can edit, duplicate, disable, or delete a log directly in your IDE.

Edit a dynamic log configuration parameters

  1. Click the menu icon ... next to the relevant log in the Lightrun sidebar.

    Action Options menu --half

  2. Select Edit from the menu that appears to open the Edit a Log dialog.

    The Edit a Log dialog should appear similar to the following image. Edit a log dialog --half

  3. Edit your log configuration data in the Edit a Log dialog.

Duplicate a Lightrun dynamic log

  1. Hover your cursor over the relevant log in the Lightrun sidebar.
  2. Right-click and select Duplicate.

    Duplicate log

    The Insert a log dialog opens, displaying the data of the duplicated snapshot. 3. Update any necessary details, such as modifying the code line or adjusting settings. 4. Click Create to save the duplicated log.

Disable a Lightrun dynamic log

  1. Hover your cursor over the relevant log in the Lightrun sidebar.
    A toggle switch should appear.
    Action toggle switch --half
  2. Click the toggle switch from blue (on) to grey (off).
  3. To resume logging, click the toggle back to blue.

Delete a Lightrun dynamic log

  1. Click the menu icon ... next to the relevant log in the Lightrun sidebar.
  2. Select Delete from the menu.

    Action Options menu --quarter

Analyze Lightrun logs

The default target for Lightrun dynamic logs is set to Plugin. This configuration allows you to view your dynamic logs output directly in your IDE through the Lightrun Console, the Lightrun Management Portal, and third-party integrated apps like Slack or Prometheus.

Alternatively, you can set the target to Stdout. This setup enables logs to be analyzed in the context of pre-existing logs, which might provide further clues towards solving issues.

Viewing logs from the Visual Studio Lightrun Console

Once you've configured your action target to Plugin and added at least one dynamic log to your code, the Lightrun Console should display real-time output from the added dynamic log.


Last update: December 18, 2024