How to use .Net API ?

How to Generate a Trace File in Visual Guard?

Estimated reading: 5 minutes 1423 views

Generating a trace file in Visual Guard helps capture detailed activity and internal processes, making it easier to analyze issues and understand application behavior and performance. This guide walks you through the steps to enable and generate a trace file, which can then be used for troubleshooting or shared with support teams for further investigation.


Why would I need to generate these files?

Below are few scenarios when you can generate the trace files:

  • Why my user is rejected during the authentication process.
  • Is my permission is granted to the current user.
  • What is the value of my permission argument.
  • Why a security action is not executed.
  • When a security action is not triggered as expected.
  • When analyzing role or profile configuration issues.
  • When investigating errors or unexpected system responses.
  • When I want to check any performance related issue or response.

Methods of generating the files.

Visual Guard allows trace files to be generated using different methods depending on the application setup and troubleshooting needs. Tracing can be enabled directly through code, via application settings, or by updating the web/config file. Each method provides a flexible way to capture detailed runtime and security-related information for analysis and diagnostics.

1. Via code

Trace files can also be generated directly through code, offering greater control over when and how tracing is enabled. This approach is useful when you want to dynamically capture trace information during specific operations or scenarios within the application. By adding the appropriate tracing logic in your code, you can record detailed execution data for targeted analysis.

  • C#
  • VB
{
    // Trace all information in a MyTrace.txt at the root of the website 
    string path = System.IO.Path.Combine("<specifiy path>", "VGLog.Txt");

    System.Diagnostics.TextWriterTraceListener listener;

    listener = new System.Diagnostics.TextWriterTraceListener(new System.IO.FileStream(path, System.IO.FileMode.Append, System.IO.FileAccess.Write, System.IO.FileShare.ReadWrite));

    Novalys.VisualGuard.Security.VGSecurityManager.TraceLevel = System.Diagnostics.TraceLevel.Info;
    Novalys.VisualGuard.Security.VGSecurityManager.TraceListener = listener;
}
Trace all information in a VGLog.txt file at the specified location
Dim path As String = System.IO.Path.Combine("<specify path>", "VGLog.txt")

Dim listener As System.Diagnostics.TextWriterTraceListener

listener = New System.Diagnostics.TextWriterTraceListener( _
    New System.IO.FileStream(path, _
                             System.IO.FileMode.Append, _
                             System.IO.FileAccess.Write, _
                             System.IO.FileShare.ReadWrite))

Novalys.VisualGuard.Security.VGSecurityManager.TraceLevel = System.Diagnostics.TraceLevel.Info
Novalys.VisualGuard.Security.VGSecurityManager.TraceListener = listener

2. Via app setting or web.config

You can generate a trace file in Visual Guard by configuring the application’s config file. This approach allows you to enable tracing without making changes to the application interface, making it especially useful for controlled environments or when direct access to settings is limited. By updating the relevant parameters in the config file, you can capture detailed trace information during runtime depending on the framework used.

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.diagnostics>
<switches>
<add name="VisualGuard" value="4" />
</switches>
<trace autoflush="false" indentsize="4">
<listeners>
<add name="VisualGuard" type="System.Diagnostics.TextWriterTraceListener" initializeData="VGLog.txt" />
<remove name="Default" />
</listeners>
</trace>
</system.diagnostics>
</configuration>



Trace level Fields

NameValueDescription
Off0Output no tracing and debugging messages.
Error1Output error-handling messages.
Warning2Output warnings and error-handling messages.
Info3Output informational messages, warnings, and error-handling messages.
Verbose4Output all debugging and tracing messages.
  • You can set the value to zero if you do not want to trace error.
  • You can set the value to 4 if you want to trace all granted permissions and executed security actions.
  • By default the trace level is 4 if the application is attached to a debugger and zero if not.

Trace path and its Permission

Specify the desired location where the trace file (VGLog.txt) will be generated and stored. Ensure that the selected path, folder, or file has the appropriate write permissions; otherwise, Visual Guard will not be able to create or update the trace file successfully. It is also recommended to use a dedicated and easily accessible location to simplify log collection and review.


Output of the file

Once tracing is enabled and the application is executed, Visual Guard generates the VGLog.txt file at the configured location. This file records detailed runtime information, including authentication steps, permission evaluations, security actions, workflow execution details, and system events processed by Visual Guard. Below is a sample output trace file.

Visual Guard: *******************************************************
Visual Guard: ==> 2006-08-23 13:27:22Z: Visual Guard initialization
Visual Guard: ==> 2006-08-23 13:27:23Z: Repository provider loaded: Novalys.VisualGuard.Security.Files.Repository.VGFileRepositoryConnection, Novalys.VisualGuard.Security.File, Version=2.5.708.6, Culture=neutral, PublicKeyToken=8e423a8f05ffd0dc
Visual Guard: Authorization attempt: user=jsmith (status=Success)
Visual Guard: Granted Role: #Sales manager (#Sales manager)
Visual Guard:     Granted permissions:
Visual Guard:         [Sales manager permissions].\Employees\Disable employees edition (id=8f95817d-ac24-4fd1-90d7-49a42eacd156)
Visual Guard:         [Sales manager permissions].\Products\Disable products and categories edition (id=bb241aa9-24ce-4b5b-96d3-4bf16db4e174)
Visual Guard:         [Common permissions].\Samples\Permission with argument(MyValue = My default value) (id=07b21eb4-4bef-4a0d-83aa-adb90c31a992)
Visual Guard:         [Common permissions].\Samples\Script Action Sample(Attribute1 = "My Value for attribute1", Attribute2 = 31/12/2006 00:00:00) (id=c755dfa1-73a3-47cd-8260-b4f6c20e3018)
Visual Guard:         [Non administrator permissions].\Users\Disable Membership edition (id=042e30c2-ca0f-4ce8-931f-8290fe98417e)
Visual Guard: Authentication attempt: user=jsmith (status=Success)
Visual Guard: ==> 2006-08-23 13:27:30Z: Set Security of Novalys.VisualGuard.NorthwindSample.Common.Data.SecuredNorthwindDataset
Visual Guard: ==> 2006-08-23 13:27:30Z: Set Security of Novalys.VisualGuard.NorthwindSample.MDIForm
Visual Guard: ==> 2006-08-23 13:27:30Z: Execute Action \Products\Disable products and categories edition.MDIForm.SetProperties(_myCategories.Enabled=False,_myProducts.En...)
Visual Guard: ==> 2006-08-23 13:27:30Z: Execute Action \Samples\Script Action Sample.MDIForm.SetProperties(_editConfigToolStripMenuItem.Visible=False)
Visual Guard: ==> 2006-08-23 13:27:30Z: == Action condition 'Enabled = true' is True => Action executed
Visual Guard: ==> 2006-08-23 13:27:30Z: Execute Action \Users\Disable Membership edition.MDIForm.SetProperties(_usersMenuItem.Enabled=False)