Use application base directory to locate self diagnostic config file (#1865)

* add current directory to locate self diagnostic config file

* update check path to prioritize current working directory then fallback to app base directory

* typo

* updated changelog

* fix linting
This commit is contained in:
Thomas Bolon 2021-03-04 00:34:51 +01:00 committed by GitHub
parent 381908c089
commit 7da935e237
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 3 deletions

View File

@ -20,6 +20,11 @@ please check the latest changes
* Added new constructor with optional parameters to allow customization of
`ParentBasedSampler` behavior. ([#1727](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1727))
* The application base directory is now tested after the current directory when
searching for the
[self diagnostic configuration file](https://github.com/open-telemetry/opentelemetry-dotnet/blob/main/src/OpenTelemetry/README.md#troubleshooting).
([#1865](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1865))
## 1.0.1
Released 2021-Feb-10

View File

@ -54,12 +54,25 @@ namespace OpenTelemetry.Internal
logLevel = EventLevel.LogAlways;
try
{
if (!File.Exists(ConfigFileName))
var configFilePath = ConfigFileName;
// First check using current working directory
if (!File.Exists(configFilePath))
{
return false;
#if NET452
configFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, ConfigFileName);
#else
configFilePath = Path.Combine(AppContext.BaseDirectory, ConfigFileName);
#endif
// Second check using application base directory
if (!File.Exists(configFilePath))
{
return false;
}
}
using FileStream file = File.Open(ConfigFileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete);
using FileStream file = File.Open(configFilePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete);
var buffer = this.configBuffer;
if (buffer == null)
{