Skip to content

Commit eb3524d

Browse files
committed
factor out GetProgramDataDirectory()
1 parent 5ef3035 commit eb3524d

File tree

1 file changed

+25
-16
lines changed

1 file changed

+25
-16
lines changed

tracer/src/Datadog.Trace/Logging/Internal/DatadogLoggingFactory.cs

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -226,22 +226,7 @@ private static string GetDefaultLogDirectory(IConfigurationSource source, IConfi
226226

227227
if (isWindows)
228228
{
229-
// On Nano Server, this returns "", so we fall back to reading from the env var set in the base image instead
230-
// - https://github.com/dotnet/runtime/issues/22690
231-
// - https://github.com/dotnet/runtime/issues/21430
232-
// - https://github.com/dotnet/runtime/pull/109673
233-
// If _that_ fails, we just hard code it to "C:\ProgramData", which is what the native components do anyway
234-
var programData = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData);
235-
if (string.IsNullOrEmpty(programData))
236-
{
237-
// fallback #1: try reading from the env var
238-
programData = EnvironmentHelpersNoLogging.ProgramData();
239-
if (string.IsNullOrEmpty(programData))
240-
{
241-
// fallback #2: hard-coded
242-
programData = @"C:\ProgramData";
243-
}
244-
}
229+
var programData = GetProgramDataDirectory();
245230

246231
logDirectory = Path.Combine(programData, "Datadog .NET Tracer", "logs");
247232
}
@@ -253,6 +238,30 @@ private static string GetDefaultLogDirectory(IConfigurationSource source, IConfi
253238
return logDirectory;
254239
}
255240

241+
private static string GetProgramDataDirectory()
242+
{
243+
// On Nano Server, this returns "", so we fall back to reading from the env var set in the base image instead
244+
// - https://github.com/dotnet/runtime/issues/22690
245+
// - https://github.com/dotnet/runtime/issues/21430
246+
// - https://github.com/dotnet/runtime/pull/109673
247+
// If _that_ fails, we just hard code it to "C:\ProgramData", which is what the native components do anyway
248+
var programData = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData);
249+
250+
if (StringUtil.IsNullOrEmpty(programData))
251+
{
252+
// fallback #1: try reading from the env var
253+
programData = EnvironmentHelpersNoLogging.ProgramData();
254+
255+
if (StringUtil.IsNullOrEmpty(programData))
256+
{
257+
// fallback #2: hard-coded
258+
programData = @"C:\ProgramData";
259+
}
260+
}
261+
262+
return programData;
263+
}
264+
256265
private static bool TryCreateLogDirectory(string logDirectory)
257266
{
258267
try

0 commit comments

Comments
 (0)