Skip to content

Commit

Permalink
Update Self-Diagnostics instructions (#2271)
Browse files Browse the repository at this point in the history
* Update Self-Diagnostics instructions

* Update Readme.md

* Update Readme.md
  • Loading branch information
TimothyMothra authored May 19, 2021
1 parent 1b8e58f commit b273a48
Showing 1 changed file with 33 additions and 57 deletions.
90 changes: 33 additions & 57 deletions troubleshooting/ETW/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,21 +116,30 @@ StatusMonitor uses TraceEventSession to record ETW logs.
- https://github.com/dotnet/roslyn/wiki/Recording-performance-traces-with-PerfView
- https://github.com/microsoft/perfview/blob/master/src/TraceEvent/TraceEventSession.cs

### Self Diagnostics
### Self-Diagnostics

As of version 2.18.0, this SDK also ships a "self-diagnostics feature", which
helps troubleshooting.
When enabled, internal events generated by ApplicationInsights SDK will be
written to a log file.
As of version 2.18.0, this SDK ships a "self-diagnostics feature" which captures internal events and writes to a log file in a specified directory.

The self-diagnostics feature can be enabled/disabled while the process
is running.
The self-diagnostics feature can be enabled/changed/disabled while the process is running.
The SDK will attempt to read the configuration file every 10 seconds, using a non-exclusive read-only mode.
The SDK will create or overwrite a file with new logs according to the configuration.

To enable self-diagnostics, go to the
[current working directory](https://en.wikipedia.org/wiki/Working_directory) of
your process and create a configuration file named `ApplicationInsightsDiagnostics.json`
with the following content:
#### Configuration

Configuration is controlled by a file named `ApplicationInsightsDiagnostics.json`.
The configuration file must be no more than 4 KiB, otherwise only the first 4 KiB of content will be read.

**To enable self-diagnostics**, go to the [current working directory](https://en.wikipedia.org/wiki/Working_directory) of your process and create a configuration file.
In most cases, you could just drop the file along your application.
On Windows, you can use [Process Explorer](https://docs.microsoft.com/sysinternals/downloads/process-explorer),
double click on the process to pop up Properties dialog, and find "Current directory" in "Image" tab.
Internally, the SDK looks for the configuration file located in [GetCurrentDirectory](https://docs.microsoft.com/dotnet/api/system.io.directory.getcurrentdirectory),
and then [AppContext.BaseDirectory](https://docs.microsoft.com/dotnet/api/system.appcontext.basedirectory).
You can also find the exact directory by calling these methods from your code.

**To disable self-diagnostics**, delete the configuration file.

Example:
```json
{
"LogDirectory": ".",
Expand All @@ -139,55 +148,22 @@ with the following content:
}
```

To disable self-diagnostics, delete the above file.
#### Configuration Parameters

Tip on finding the "current working directory":
In most cases, you could just drop the file along your application.
On Windows, you can use [Process Explorer](https://docs.microsoft.com/sysinternals/downloads/process-explorer),
double click on the process to pop up Properties dialog and find "Current
directory" in "Image" tab.
Internally, it looks for the configuration file located in
[GetCurrentDirectory](https://docs.microsoft.com/dotnet/api/system.io.directory.getcurrentdirectory),
and then [AppContext.BaseDirectory](https://docs.microsoft.com/dotnet/api/system.appcontext.basedirectory).
You can also find the exact directory by calling these methods from your code.
A `FileSize`-KiB log file named as `ExecutableName.ProcessId.log` (e.g. `foobar.exe.12345.log`) will be generated at the specified directory `LogDirectory`.

#### Configuration Parameters
1. `LogDirectory` is the directory where the output log file will be stored.
It can be an absolute path or a relative path to the current directory.

2. `FileSize` is a positive integer, which specifies the log file size in [KiB](https://en.wikipedia.org/wiki/Kibibyte).
This value must be between 1 MiB and 128 MiB (inclusive), or it will be rounded to the closest upper or lower limit.

3. `LogLevel` is the lowest level of the events to be captured.
This value must match one of the [fields](https://docs.microsoft.com/dotnet/api/system.diagnostics.tracing.eventlevel#fields) of the `EventLevel` enum.
Lower severity levels encompass higher severity levels (e.g. `Warning` includes the `Error` and `Critical` levels).

1. `LogDirectory` is the directory where the output log file will be stored. It
can be an absolute path or a relative path to the current directory.

2. `FileSize` is a positive integer, which specifies the log file size in
[KiB](https://en.wikipedia.org/wiki/Kibibyte).

3. `LogLevel` is the lowest level of the events to be captured. It has to be one
of the
[values](https://docs.microsoft.com/dotnet/api/system.diagnostics.tracing.eventlevel#fields)
of the [`EventLevel`
enum](https://docs.microsoft.com/dotnet/api/system.diagnostics.tracing.eventlevel).
The level signifies the severity of an event. Lower severity levels encompass
higher severity levels. For example, `Warning` includes the `Error` and
`Critical` levels.

#### Remarks

A `FileSize`-KiB log file named as `ExecutableName.ProcessId.log` (e.g.
`foobar.exe.12345.log`) will be generated at the specified directory
`LogDirectory`, into which logs are written to.

The SDK will attempt to open the configuration file in non-exclusive read-only
mode, read the file and parse it as the configuration file every 10 seconds. If
the SDK fails to parse the `LogDirectory`, `FileSize` or `LogLevel` fields as
the specified format, the configuration file will be treated as invalid and no
log file would be generated. Otherwise, it will create or overwrite the log file
as described above.

Note that the `FileSize` has to be between 1 MiB and 128 MiB (inclusive), or it
will be rounded to the closest upper or lower limit. When the `LogDirectory` or
`FileSize` is found to be changed, the SDK will create or overwrite a file with
new logs according to the new configuration. The configuration file has to be no
more than 4 KiB. In case the file is larger than 4 KiB, only the first 4 KiB of
content will be read.
**Warning**: If the SDK fails to parse any of these fields, the configuration file will be treated as invalid and self-diagnostics will be disabled.

## References

This document is referenced by: https://docs.microsoft.com/azure/azure-monitor/app/asp-net-troubleshoot-no-data#PerfView
This document is referenced by: https://docs.microsoft.com/azure/azure-monitor/app/asp-net-troubleshoot-no-data#PerfView

0 comments on commit b273a48

Please sign in to comment.