Skip to content

Commit

Permalink
Move initialization of the WindowsDefaultDirectory variable in Datado…
Browse files Browse the repository at this point in the history
…gLogging to the constructor to catch possible SecurityExceptions.
  • Loading branch information
zacharycmontoya committed Jan 22, 2020
1 parent a9efb8a commit 0b2cbe4
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/Datadog.Trace/Logging/DatadogLogging.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ namespace Datadog.Trace.Logging
internal static class DatadogLogging
{
private const string NixDefaultDirectory = "/var/log/datadog/";
private static readonly string WindowsDefaultDirectory =
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), @"Datadog .NET Tracer", "logs");
private static readonly string WindowsDefaultDirectory;

private static readonly long? MaxLogFileSize = 10 * 1024 * 1024;
private static readonly LogEventLevel MinimumLogEventLevel = LogEventLevel.Warning;
Expand Down Expand Up @@ -51,8 +50,13 @@ static DatadogLogging()
logDirectory = Path.GetDirectoryName(nativeLogFile);
}

// This entire block may throw a SecurityException if not granted the System.Security.Permissions.FileIOPermission because of the following API calls
// - Directory.Exists
// - Environment.GetFolderPath
// - Path.GetTempPath
if (logDirectory == null)
{
WindowsDefaultDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), @"Datadog .NET Tracer", "logs");
if (Directory.Exists(WindowsDefaultDirectory))
{
logDirectory = WindowsDefaultDirectory;
Expand Down

0 comments on commit 0b2cbe4

Please sign in to comment.