@@ -222,22 +222,9 @@ private static string GetDefaultLogDirectory(IConfigurationSource source, IConfi
222222
223223 if ( isWindows )
224224 {
225- // On Nano Server, this returns "", so we fall back to reading from the env var set in the base image instead
226- // - https://github.com/dotnet/runtime/issues/22690
227- // - https://github.com/dotnet/runtime/issues/21430
228- // - https://github.com/dotnet/runtime/pull/109673
229- // If _that_ fails, we just hard code it to "C:\ProgramData", which is what the native components do anyway
230- var programData = Environment . GetFolderPath ( Environment . SpecialFolder . CommonApplicationData ) ;
231- if ( string . IsNullOrEmpty ( programData ) )
232- {
233- // fallback #1: try reading from the env var
234- programData = Environment . GetEnvironmentVariable ( "ProgramData" ) ;
235- if ( string . IsNullOrEmpty ( programData ) )
236- {
237- // fallback #2: hard-coded
238- programData = @"C:\ProgramData" ;
239- }
240- }
225+ string ? programData ;
226+
227+ programData = GetProgramDataDirectory ( ) ;
241228
242229 logDirectory = Path . Combine ( programData , "Datadog .NET Tracer" , "logs" ) ;
243230 }
@@ -249,6 +236,30 @@ private static string GetDefaultLogDirectory(IConfigurationSource source, IConfi
249236 return logDirectory ;
250237 }
251238
239+ private static string GetProgramDataDirectory ( )
240+ {
241+ // On Nano Server, this returns "", so we fall back to reading from the env var set in the base image instead
242+ // - https://github.com/dotnet/runtime/issues/22690
243+ // - https://github.com/dotnet/runtime/issues/21430
244+ // - https://github.com/dotnet/runtime/pull/109673
245+ // If _that_ fails, we just hard code it to "C:\ProgramData", which is what the native components do anyway
246+ var programData = Environment . GetFolderPath ( Environment . SpecialFolder . CommonApplicationData ) ;
247+
248+ if ( string . IsNullOrEmpty ( programData ) )
249+ {
250+ // fallback #1: try reading from the env var
251+ programData = Environment . GetEnvironmentVariable ( "ProgramData" ) ;
252+
253+ if ( string . IsNullOrEmpty ( programData ) )
254+ {
255+ // fallback #2: hard-coded
256+ programData = @"C:\ProgramData" ;
257+ }
258+ }
259+
260+ return programData ;
261+ }
262+
252263 private static bool TryCreateLogDirectory ( string logDirectory )
253264 {
254265 try
0 commit comments