Skip to content

Commit

Permalink
Use AppDomain.CurrentDomain.BaseDirectory to get path of appsettings*…
Browse files Browse the repository at this point in the history
….json (#375)

* Use AppDomain.CurrentDomain.BaseDirectory

* Update CHANGELOG.md

* Respond to PR feedback
  • Loading branch information
nr-ahemsath authored Dec 7, 2020
1 parent 864a593 commit 0ea221f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 16 deletions.
16 changes: 7 additions & 9 deletions src/Agent/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
New Feature Description

### Fixes
Fixes Issue [#224](https://github.com/newrelic/newrelic-dotnet-agent/issues/224): leading "SET" commands will be ignored when parsing compound SQL statements. ([#370](https://github.com/newrelic/newrelic-dotnet-agent/pull/370))

Fixes Issue [#226](https://github.com/newrelic/newrelic-dotnet-agent/issues/226): the profiler ignores drive letter in `HOME_EXPANDED` when detecting running in Azure Web Apps. ([#373](https://github.com/newrelic/newrelic-dotnet-agent/pull/373))

Fix Issue [#93](https://github.com/newrelic/newrelic-dotnet-agent/issues/93): when the parent methods are blocked by their asynchronous child methods, the agent deducts the child methods' duration from the parent methods' exclusive duration.([#374](https://github.com/newrelic/newrelic-dotnet-agent/pull/374))

Fixes Issue [#9](https://github.com/newrelic/newrelic-dotnet-agent/issues/9) where the agent failed to read settings from `appsettings.{environment}.json` files. ([#372](https://github.com/newrelic/newrelic-dotnet-agent/pull/372))
* Fixes Issue [#224](https://github.com/newrelic/newrelic-dotnet-agent/issues/224): leading "SET" commands will be ignored when parsing compound SQL statements. ([#370](https://github.com/newrelic/newrelic-dotnet-agent/pull/370))
* Fixes Issue [#226](https://github.com/newrelic/newrelic-dotnet-agent/issues/226): the profiler ignores drive letter in `HOME_EXPANDED` when detecting running in Azure Web Apps. ([#373](https://github.com/newrelic/newrelic-dotnet-agent/pull/373))
* Fixes Issue [#93](https://github.com/newrelic/newrelic-dotnet-agent/issues/93): when the parent methods are blocked by their asynchronous child methods, the agent deducts the child methods' duration from the parent methods' exclusive duration.([#374](https://github.com/newrelic/newrelic-dotnet-agent/pull/374))
* Fixes Issue [#9](https://github.com/newrelic/newrelic-dotnet-agent/issues/9) where the agent failed to read settings from `appsettings.{environment}.json` files. ([#372](https://github.com/newrelic/newrelic-dotnet-agent/pull/372))
* Fixes Issue [#116](https://github.com/newrelic/newrelic-dotnet-agent/issues/116) where the agent failed to read settings from `appsettings.json` in certain hosting scenarios. ([#375](https://github.com/newrelic/newrelic-dotnet-agent/pull/375))


## [8.35] - 2020-11-09
Expand All @@ -26,8 +24,8 @@ Fixes Issue [#9](https://github.com/newrelic/newrelic-dotnet-agent/issues/9) whe
We have validated that this version of the agent is compatible with .NET 5 GA. See the [compatibility and requirements for .NET Core](https://docs.newrelic.com/docs/agents/net-agent/getting-started/net-agent-compatibility-requirements-net-core) page for more details.

### Fixes
Fixes Issue [#337](https://github.com/newrelic/newrelic-dotnet-agent/issues/337) by removing obsolete code which was causing memory growth associated with a large number of transaction names.
PR [#348](https://github.com/newrelic/newrelic-dotnet-agent/pull/348): guards against potential exceptions being thrown from the agent API when the agent is not attached.
* Fixes Issue [#337](https://github.com/newrelic/newrelic-dotnet-agent/issues/337) by removing obsolete code which was causing memory growth associated with a large number of transaction names.
* PR [#348](https://github.com/newrelic/newrelic-dotnet-agent/pull/348): guards against potential exceptions being thrown from the agent API when the agent is not attached.

## [8.34] - 2020-10-26

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

#if NETSTANDARD2_0
using System;
using System.IO;
using Microsoft.Extensions.Configuration;
using NewRelic.Core.Logging;
Expand All @@ -23,25 +24,37 @@ private static IConfiguration Configuration

private static IConfigurationRoot InitializeConfiguration()
{
// Get application base directory, where appsettings*.json will be if they exist
var applicationDirectory = string.Empty;
try
{
applicationDirectory = AppDomain.CurrentDomain.BaseDirectory;
}
catch (AppDomainUnloadedException)
{
// Fall back to previous behavior of agents <=8.35.0
applicationDirectory = Directory.GetCurrentDirectory();
}

var builder = new ConfigurationBuilder()
.SetBasePath(applicationDirectory)
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: false);

// Determine if there might be an environment-specific appsettings file
var env = new SystemInterfaces.Environment();
var currentDirectory = Directory.GetCurrentDirectory();
var environment = env.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
if (string.IsNullOrEmpty(environment))
{
environment = env.GetEnvironmentVariable("EnvironmentName");
}

var builder = new ConfigurationBuilder()
.SetBasePath(currentDirectory)
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: false);

if (!string.IsNullOrEmpty(environment))
{
builder.AddJsonFile($"appsettings.{environment}.json", optional: true, reloadOnChange: false);
}

var appSettingsPath = Path.Combine(currentDirectory, "appsettings.json");
var appSettingsEnvPath = Path.Combine(currentDirectory, $"appsettings.{environment}.json");
var appSettingsPath = Path.Combine(applicationDirectory, "appsettings.json");
var appSettingsEnvPath = Path.Combine(applicationDirectory, $"appsettings.{environment}.json");
_appSettingsFilePaths = !string.IsNullOrEmpty(environment) ? string.Join(", ", appSettingsPath, appSettingsEnvPath) : appSettingsPath;

return builder.Build();
Expand Down

0 comments on commit 0ea221f

Please sign in to comment.