Docs Menu
Docs Home
/
MongoDB C# Analyzer

Configure the MongoDB C# Analyzer

On this page

  • Overview
  • Configuration
  • Options
  • Telemetry

Learn how to configure the C# Analyzer in your .NET project and what configuration options are available.

To configure the C# Analyzer, perform the following actions:

  1. Install the C# Analyzer as described in the installation guide.

  2. Create a file specifying your configuration for the C# Analyzer named mongodb.analyzer.json.

    Important

    Naming

    You must name your configuration file mongodb.analyzer.json.

  3. Add your configuration to your mongodb.analyzer.json file.

    The following sample configuration makes the C# Analyzer use the LINQ3 provider.

    { "DefaultLinqVersion": "V3" }
  4. Add the following to the .csproj file for your .NET application within the Project tag:

    <ItemGroup>
    <AdditionalFiles Include="<path to your mongodb.analyzer.json file>" />
    </ItemGroup>

Note

Configuration is Optional

If you do not specify a configuration file, the C# Analyzer uses the default value for all configuration options.

To learn more about .NET project files, see Understanding the Project File from Microsoft.

To learn more about the AdditionalFiles tag, see Using Additional Files in the Roslyn documentation.

The following is a description of all configuration options supported by the C# Analyzer:

Name
Description
DefaultLinqVersion
Type: string

Description: The LINQ provider the C# Analyzer uses.

Tip

To learn more about LINQ, see the Analyze Your Code page.

Accepted Values: "V2" or "V3"
Default: "V2"
EnableVariableTracking
Type: boolean

Description: Specifies if the C# Analyzer tracks and composes builder expression variables.

Tip

To learn more about builder expressions, see the Analyze Your Code page.

Accepted Values: true or false
Default: true
LogFileName
Type: string

Description: Specifies the path to which the C# Analyzer writes its internal logs.

Important

To output logs, you must specify both a logfile and the OutputInternalLogsToFile option.

Use the following sample configuration to make the C# Analyzer output information to a logfile:

"OutputInternalLogsToFile": true,
"LogFileName": "<path to your logfile>"
Accepted Values: A valid file path
Default: ""
OutputDriverVersion
Type: boolean

Description: Specifies if the C# Analyzer includes your .NET/C# driver version in diagnostic messages.

Accepted Values: true or false
Default: false
OutputInternalExceptions
Type: boolean

Description: Specifies if the C# Analyzer includes internal exceptions in diagnostic messages.

Accepted Values: true or false
Default: false
OutputInternalLogsToFile
Type: boolean

Description: Specifies if the C# Analyzer writes its internal logs to a file.

Important

To output logs, you must specify both a logfile and the OutputInternalLogsToFile option.

Use the following sample configuration to make the C# Analyzer output information to a logfile:

"OutputInternalLogsToFile": true,
"LogFileName": "<path to your logfile>"
Accepted Values: true or false
Default: false
PocoAnalysisVerbosity
Type: string

Description: Specifies which POCOs the C# Analyzer previews as JSON. You can set this option to one of the following values:
  • "All": Preview all POCOs

  • "Medium": Preview only POCOs that are part of a LINQ or builders expression or have BSON attributes

  • "None": Do not preview POCOs

Accepted Values: "All", "Medium", or "None"
Default: "Medium"
SendTelemetry
Type: boolean

Description: Specifies if the C# Analyzer collects and sends anonymized information to MongoDB Inc. to improve products.

Tip

To learn more about telemetry in the C# Analyzer, see the Telemetry section of this guide.

Accepted Values: true or false
Default: true

To learn more about the configuration options the C# Analyzer supports, see the MongoDB C# Analyzer source code.

When the C# Analyzer analyzes your source code, the tool by default collects and sends anonymized information to MongoDB Inc. to improve products.

To disable this feature, specify the following option in your configuration file:

"SendTelemetry": false

To view a complete list of all information collected by the C# Analyzer when you have enabled telemetry, see the FAQ page.

To learn more about how MongoDB Inc. uses collected data, see the Privacy Policy.

Back

Rules & Message Content