Skip to content

Commit 29575d4

Browse files
committed
fix bad merge
1 parent 3d77f7a commit 29575d4

File tree

1 file changed

+21
-30
lines changed

1 file changed

+21
-30
lines changed

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

Lines changed: 21 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,12 @@ internal static string GetLogDirectory(IConfigurationTelemetry telemetry)
171171

172172
private static string GetLogDirectory(IConfigurationSource source, IConfigurationTelemetry telemetry)
173173
{
174+
// try reading from DD_TRACE_LOG_DIRECTORY
174175
var logDirectory = new ConfigurationBuilder(source, telemetry).WithKeys(ConfigurationKeys.LogDirectory).AsString();
175176

176177
if (string.IsNullOrEmpty(logDirectory))
177178
{
179+
// fallback #1: try getting the directory from DD_TRACE_LOG_PATH
178180
#pragma warning disable 618 // ProfilerLogPath is deprecated but still supported
179181
var nativeLogFile = new ConfigurationBuilder(source, telemetry).WithKeys(ConfigurationKeys.ProfilerLogPath).AsString();
180182
#pragma warning restore 618
@@ -187,9 +189,11 @@ private static string GetLogDirectory(IConfigurationSource source, IConfiguratio
187189

188190
if (string.IsNullOrEmpty(logDirectory))
189191
{
192+
// fallback #2: use the default log directory
190193
logDirectory = GetDefaultLogDirectory(source, telemetry);
191194
}
192195

196+
// try creating the directory if it doesn't exist
193197
if (logDirectory != null && (Directory.Exists(logDirectory) || TryCreateLogDirectory(logDirectory)))
194198
{
195199
return logDirectory;
@@ -207,48 +211,35 @@ private static string GetDefaultLogDirectory(IConfigurationSource source, IConfi
207211
// - Directory.CreateDirectory
208212
// - Environment.GetFolderPath
209213
// - Path.GetTempPath
210-
string logDirectory;
211214
var isWindows = FrameworkDescription.Instance.IsWindows();
212215

213216
if (ImmutableAzureAppServiceSettings.IsRunningInAzureAppServices(source, telemetry))
214217
{
215-
var isWindows = FrameworkDescription.Instance.IsWindows();
218+
return isWindows ? @"C:\home\LogFiles\datadog" : "/home/LogFiles/datadog";
219+
}
216220

217-
if (ImmutableAzureAppServiceSettings.IsRunningInAzureAppServices(source, telemetry) ||
218-
ImmutableAzureAppServiceSettings.IsRunningInAzureFunctions(source, telemetry))
219-
{
220-
return isWindows ? @"C:\home\LogFiles\datadog" : "/home/LogFiles/datadog";
221-
}
221+
string logDirectory;
222222

223-
if (isWindows)
223+
if (isWindows)
224+
{
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))
224232
{
225-
// On Nano Server, this returns "", so we fallback 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);
233+
// fallback #1: try reading from the env var
234+
programData = Environment.GetEnvironmentVariable("ProgramData");
231235
if (string.IsNullOrEmpty(programData))
232236
{
233-
programData = Environment.GetEnvironmentVariable("ProgramData");
234-
if (string.IsNullOrEmpty(programData))
235-
{
236-
programData = @"C:\ProgramData";
237-
}
237+
// fallback #2: hard-coded
238+
programData = @"C:\ProgramData";
238239
}
239-
240-
logDirectory = Path.Combine(programData, "Datadog .NET Tracer", "logs");
241-
}
242-
else
243-
{
244-
logDirectory = "/var/log/datadog/dotnet";
245240
}
246-
}
247241

248-
if (isWindows)
249-
{
250-
var commonApplicationDataFolder = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData);
251-
logDirectory = Path.Combine(commonApplicationDataFolder, "Datadog .NET Tracer", "logs");
242+
logDirectory = Path.Combine(programData, "Datadog .NET Tracer", "logs");
252243
}
253244
else
254245
{

0 commit comments

Comments
 (0)