Skip to content

Commit

Permalink
use RuntimeInformation and use elastic-otel-dotnet as folder name
Browse files Browse the repository at this point in the history
  • Loading branch information
Mpdreamz committed Jun 5, 2024
1 parent 4ca5326 commit c977467
Showing 1 changed file with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
using Elastic.OpenTelemetry.Diagnostics.Logging;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using static System.Environment;
using static System.Runtime.InteropServices.RuntimeInformation;
using static Elastic.OpenTelemetry.Configuration.EnvironmentVariables;

namespace Elastic.OpenTelemetry.Configuration;
Expand Down Expand Up @@ -63,7 +65,7 @@ public class ElasticOpenTelemetryOptions
public ElasticOpenTelemetryOptions(IDictionary? environmentVariables = null)
{
_defaultLogDirectory = GetDefaultLogDirectory();
_environmentVariables = environmentVariables ?? Environment.GetEnvironmentVariables();
_environmentVariables = environmentVariables ?? GetEnvironmentVariables();
SetFromEnvironment(ELASTIC_OTEL_LOG_DIRECTORY, ref _logDirectory, ref _logDirectorySource, StringParser);
SetFromEnvironment(ELASTIC_OTEL_LOG_LEVEL, ref _logLevel, ref _logLevelSource, LogLevelParser);
SetFromEnvironment(ELASTIC_OTEL_LOG_TARGETS, ref _logTargets, ref _logTargetsSource, LogTargetsParser);
Expand Down Expand Up @@ -126,12 +128,15 @@ public bool GlobalLogEnabled
}
}

private static string GetDefaultLogDirectory() =>
Environment.OSVersion.Platform == PlatformID.Win32NT
? Path.Combine(Environment.GetEnvironmentVariable("PROGRAMDATA")!, "elastic", "apm-agent-dotnet", "logs")
: RuntimeInformation.IsOSPlatform(OSPlatform.OSX)
? Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "elastic", "apm-agent-dotnet")
: "/var/log/elastic/apm-agent-dotnet";
private static string GetDefaultLogDirectory()
{
var applicationMoniker = "elastic-otel-dotnet";
if (IsOSPlatform(OSPlatform.Windows))
return Path.Combine(GetFolderPath(SpecialFolder.ApplicationData), "elastic", applicationMoniker);
if (IsOSPlatform(OSPlatform.OSX))
return Path.Combine(GetFolderPath(SpecialFolder.LocalApplicationData), "elastic", applicationMoniker);
return $"/var/log/elastic/{applicationMoniker}";
}

/// <summary>
/// The default log directory if file logging was enabled but non was specified
Expand Down

0 comments on commit c977467

Please sign in to comment.