Skip to content

Commit

Permalink
Catching exception when failing to read config in partial trust (#1119)
Browse files Browse the repository at this point in the history
* Catching exception when run in partial trust

* Address style cop issues

* App domain is needed for event sources
  • Loading branch information
stimms authored and cijothomas committed Apr 26, 2019
1 parent 3115fe1 commit 1a97e6b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace Microsoft.ApplicationInsights.Extensibility.Implementation.Platform
using Microsoft.ApplicationInsights.Extensibility;
using Microsoft.ApplicationInsights.Extensibility.Implementation;
using Microsoft.ApplicationInsights.Extensibility.Implementation.Tracing;

/// <summary>
/// The .NET 4.0 and 4.5 implementation of the <see cref="IPlatform"/> interface.
/// </summary>
Expand Down Expand Up @@ -44,8 +44,17 @@ public PlatformImplementation()
/// </summary>
public string ReadConfigurationXml()
{
// Config file should be in the base directory of the app domain
string configFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ApplicationInsights.config");
string configFilePath;
try
{
// Config file should be in the base directory of the app domain
configFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ApplicationInsights.config");
}
catch (SecurityException)
{
CoreEventSource.Log.ApplicationInsightsConfigNotAccessibleWarning();
return string.Empty;
}

try
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -525,14 +525,25 @@ public void TelemetrySinkCalledAfterBeingDisposed(string appDomainName = "Incorr
}

/// <summary>
/// Logs the detais when there operation to stop does not match the current operation.
/// Logs the details when there operation to stop does not match the current operation.
/// </summary>
[Event(44, Message = "Operation to stop does not match the current operation. Details {0}.", Level = EventLevel.Warning)]
public void InvalidOperationToStopDetails(string details, string appDomainName = "Incorrect")
{
this.WriteEvent(44, details, this.nameProvider.Name);
}

[Event(
45,
Message = "File system containing ApplicationInsights configuration file is inaccessible.",
Level = EventLevel.Warning)]
public void ApplicationInsightsConfigNotAccessibleWarning(string appDomainName = "Incorrect")
{
this.WriteEvent(
45,
this.nameProvider.Name);
}

/// <summary>
/// Keywords for the PlatformEventSource.
/// </summary>
Expand Down

0 comments on commit 1a97e6b

Please sign in to comment.