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:
- Attached an agent to your application.
- Installed the plugin in your local Visual Studio instance.
- Authenticated the Visual Studio plugin against your Lightrun account.
- 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.
-
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
- Open the Lightrun sidebar in your Visual Studio IDE.
- Click the Plus icon at the top of the plugin, or go to the Agents or Tags tab and select an agent or tag.
- Click the Add Action.
-
Select Log in the menu that appears.
-
Directly in the Code Editor
- 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).
- Right-click to open the Visual Studio context menu.
-
From the Visual Studio context menu, click Lightrun.
The Visual Studio Command Palette opens with a list of Lightrun plugin options. -
From the Command Palette, select Add Log.
-
-
Configure the log parameters.
The Insert a Log dialog should appear similar to the following image.
-
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 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 conditionmyVar % 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. -
Click Create to insert the dynamic log into your code.
Manage Lightrun logs¶
Access your log in the code
- In the Visual Studio editor, a icon will appear next to the selected code line.
-
A new log action will appear under the selected source (agent or tag) in the Lightrun sidebar.
-
You can edit, duplicate, disable, or delete a log directly in your IDE.
Edit a dynamic log configuration parameters¶
-
Click the menu icon ... next to the relevant log in the Lightrun sidebar.
-
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 your log configuration data in the Edit a Log dialog.
Duplicate a Lightrun dynamic log¶
- Hover your cursor over the relevant log in the Lightrun sidebar.
-
Right-click and select Duplicate.
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¶
- Hover your cursor over the relevant log in the Lightrun sidebar.
A toggle switch should appear.
- Click the toggle switch from blue (on) to grey (off).
- To resume logging, click the toggle back to blue.
Delete a Lightrun dynamic log¶
- Click the menu icon ... next to the relevant log in the Lightrun sidebar.
-
Select Delete from the menu.
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.