From 00b37761f8b6f13aa04cd48e939f930acda5fd0b Mon Sep 17 00:00:00 2001 From: Andrew Lock Date: Thu, 17 Oct 2024 14:58:09 +0100 Subject: [PATCH 1/2] Include PID in managed logs filename --- .../Logging/Internal/DatadogLoggingFactory.cs | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/tracer/src/Datadog.Trace/Logging/Internal/DatadogLoggingFactory.cs b/tracer/src/Datadog.Trace/Logging/Internal/DatadogLoggingFactory.cs index 755a45ba4545..b59384420f01 100644 --- a/tracer/src/Datadog.Trace/Logging/Internal/DatadogLoggingFactory.cs +++ b/tracer/src/Datadog.Trace/Logging/Internal/DatadogLoggingFactory.cs @@ -6,6 +6,7 @@ #nullable enable using System; +using System.Globalization; using System.IO; using Datadog.Trace.Agent; using Datadog.Trace.Configuration; @@ -101,17 +102,28 @@ static bool Contains(string?[]? array, string toMatch) if (config.File is { } fileConfig) { - // Ends in a dash because of the date postfix - var managedLogPath = Path.Combine(fileConfig.LogDirectory, $"dotnet-tracer-managed-{domainMetadata.ProcessName}-.log"); + var managedLogPath = Path.Combine(fileConfig.LogDirectory, $"dotnet-tracer-managed-{domainMetadata.ProcessName}-{domainMetadata.ProcessId.ToString(CultureInfo.InvariantCulture)}.log"); + +#if NETFRAMEWORK + // In IIS, the log file is shared between all app domains, so we need this setup + var shared = true; + var buffered = false; +#else + // In .NET Core, we always have one tracer per process, so we can yolo this a bit more + var shared = false; + var buffered = true; +#endif loggerConfiguration .WriteTo.File( managedLogPath, outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] {Message:lj} {Exception} {Properties}{NewLine}", - rollingInterval: RollingInterval.Day, + rollingInterval: RollingInterval.Infinite, // don't do daily rolling, rely on the file size limit for rolling instead rollOnFileSizeLimit: true, fileSizeLimitBytes: fileConfig.MaxLogFileSizeBytes, - shared: true); + shared: shared, + buffered: buffered, + flushToDiskInterval: buffered ? TimeSpan.FromSeconds(1) : null); // make sure we still flush to disk if we're buffered } try From b82b9618c46d5f9eb1ca4432c8cea7a3d181eafe Mon Sep 17 00:00:00 2001 From: Andrew Lock Date: Fri, 18 Oct 2024 09:30:52 +0100 Subject: [PATCH 2/2] Remove buffering as it breaks dynamic instrumentation tests --- .../Logging/Internal/DatadogLoggingFactory.cs | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/tracer/src/Datadog.Trace/Logging/Internal/DatadogLoggingFactory.cs b/tracer/src/Datadog.Trace/Logging/Internal/DatadogLoggingFactory.cs index b59384420f01..e1e2610e1c3e 100644 --- a/tracer/src/Datadog.Trace/Logging/Internal/DatadogLoggingFactory.cs +++ b/tracer/src/Datadog.Trace/Logging/Internal/DatadogLoggingFactory.cs @@ -104,16 +104,6 @@ static bool Contains(string?[]? array, string toMatch) { var managedLogPath = Path.Combine(fileConfig.LogDirectory, $"dotnet-tracer-managed-{domainMetadata.ProcessName}-{domainMetadata.ProcessId.ToString(CultureInfo.InvariantCulture)}.log"); -#if NETFRAMEWORK - // In IIS, the log file is shared between all app domains, so we need this setup - var shared = true; - var buffered = false; -#else - // In .NET Core, we always have one tracer per process, so we can yolo this a bit more - var shared = false; - var buffered = true; -#endif - loggerConfiguration .WriteTo.File( managedLogPath, @@ -121,9 +111,7 @@ static bool Contains(string?[]? array, string toMatch) rollingInterval: RollingInterval.Infinite, // don't do daily rolling, rely on the file size limit for rolling instead rollOnFileSizeLimit: true, fileSizeLimitBytes: fileConfig.MaxLogFileSizeBytes, - shared: shared, - buffered: buffered, - flushToDiskInterval: buffered ? TimeSpan.FromSeconds(1) : null); // make sure we still flush to disk if we're buffered + shared: true); } try