From c9caffb374401b06aa0619da9280a0d35faf37e6 Mon Sep 17 00:00:00 2001 From: Andrew Lock Date: Wed, 20 Dec 2023 12:15:13 +0000 Subject: [PATCH 1/4] Add nullable reference type annotations to logging files --- .../Logging/Internal/DatadogLogging.cs | 2 + .../Logging/Internal/DatadogSerilogLogger.cs | 72 ++++++++++--------- .../Logging/Internal/IDatadogLogger.cs | 50 ++++++------- .../Logging/Internal/ILogRateLimiter.cs | 2 + .../Logging/Internal/LogRateLimiter.cs | 9 +-- .../Logging/Internal/NullLogRateLimiter.cs | 2 + 6 files changed, 75 insertions(+), 62 deletions(-) diff --git a/tracer/src/Datadog.Trace/Logging/Internal/DatadogLogging.cs b/tracer/src/Datadog.Trace/Logging/Internal/DatadogLogging.cs index a1d2a00fde96..05f82183e772 100644 --- a/tracer/src/Datadog.Trace/Logging/Internal/DatadogLogging.cs +++ b/tracer/src/Datadog.Trace/Logging/Internal/DatadogLogging.cs @@ -3,6 +3,8 @@ // This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. // +#nullable enable + using System; using System.IO; using System.Threading.Tasks; diff --git a/tracer/src/Datadog.Trace/Logging/Internal/DatadogSerilogLogger.cs b/tracer/src/Datadog.Trace/Logging/Internal/DatadogSerilogLogger.cs index e488ce46eaf9..ee0f6cf592cb 100644 --- a/tracer/src/Datadog.Trace/Logging/Internal/DatadogSerilogLogger.cs +++ b/tracer/src/Datadog.Trace/Logging/Internal/DatadogSerilogLogger.cs @@ -3,6 +3,8 @@ // This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. // +#nullable enable + using System; using System.Runtime.CompilerServices; using System.Threading; @@ -45,22 +47,22 @@ public void Debug(string messageTemplate, T0 property0, T1 property1 public void Debug(string messageTemplate, T0 property0, T1 property1, T2 property2, T3 property3, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = "") => Write(LogEventLevel.Debug, exception: null, messageTemplate, property0, property1, property2, property3, sourceLine, sourceFile); - public void Debug(string messageTemplate, object[] args, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = "") + public void Debug(string messageTemplate, object?[] args, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = "") => Write(LogEventLevel.Debug, exception: null, messageTemplate, args, sourceLine, sourceFile); - public void Debug(Exception exception, string messageTemplate, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = "") + public void Debug(Exception? exception, string messageTemplate, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = "") => Write(LogEventLevel.Debug, exception, messageTemplate, NoPropertyValues, sourceLine, sourceFile); - public void Debug(Exception exception, string messageTemplate, T property, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = "") + public void Debug(Exception? exception, string messageTemplate, T property, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = "") => Write(LogEventLevel.Debug, exception, messageTemplate, property, sourceLine, sourceFile); - public void Debug(Exception exception, string messageTemplate, T0 property0, T1 property1, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = "") + public void Debug(Exception? exception, string messageTemplate, T0 property0, T1 property1, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = "") => Write(LogEventLevel.Debug, exception, messageTemplate, property0, property1, sourceLine, sourceFile); - public void Debug(Exception exception, string messageTemplate, T0 property0, T1 property1, T2 property2, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = "") + public void Debug(Exception? exception, string messageTemplate, T0 property0, T1 property1, T2 property2, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = "") => Write(LogEventLevel.Debug, exception, messageTemplate, property0, property1, property2, sourceLine, sourceFile); - public void Debug(Exception exception, string messageTemplate, object[] args, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = "") + public void Debug(Exception? exception, string messageTemplate, object?[] args, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = "") => Write(LogEventLevel.Debug, exception, messageTemplate, args, sourceLine, sourceFile); public void Information(string messageTemplate, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = "") @@ -75,22 +77,22 @@ public void Information(string messageTemplate, T0 property0, T1 propert public void Information(string messageTemplate, T0 property0, T1 property1, T2 property2, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = "") => Write(LogEventLevel.Information, exception: null, messageTemplate, property0, property1, property2, sourceLine, sourceFile); - public void Information(string messageTemplate, object[] args, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = "") + public void Information(string messageTemplate, object?[] args, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = "") => Write(LogEventLevel.Information, exception: null, messageTemplate, args, sourceLine, sourceFile); - public void Information(Exception exception, string messageTemplate, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = "") + public void Information(Exception? exception, string messageTemplate, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = "") => Write(LogEventLevel.Information, exception, messageTemplate, NoPropertyValues, sourceLine, sourceFile); - public void Information(Exception exception, string messageTemplate, T property, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = "") + public void Information(Exception? exception, string messageTemplate, T property, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = "") => Write(LogEventLevel.Information, exception, messageTemplate, property, sourceLine, sourceFile); - public void Information(Exception exception, string messageTemplate, T0 property0, T1 property1, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = "") + public void Information(Exception? exception, string messageTemplate, T0 property0, T1 property1, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = "") => Write(LogEventLevel.Information, exception, messageTemplate, property0, property1, sourceLine, sourceFile); - public void Information(Exception exception, string messageTemplate, T0 property0, T1 property1, T2 property2, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = "") + public void Information(Exception? exception, string messageTemplate, T0 property0, T1 property1, T2 property2, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = "") => Write(LogEventLevel.Information, exception, messageTemplate, property0, property1, property2, sourceLine, sourceFile); - public void Information(Exception exception, string messageTemplate, object[] args, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = "") + public void Information(Exception? exception, string messageTemplate, object?[] args, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = "") => Write(LogEventLevel.Information, exception, messageTemplate, args, sourceLine, sourceFile); public void Warning(string messageTemplate, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = "") @@ -105,22 +107,22 @@ public void Warning(string messageTemplate, T0 property0, T1 property1, public void Warning(string messageTemplate, T0 property0, T1 property1, T2 property2, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = "") => Write(LogEventLevel.Warning, exception: null, messageTemplate, property0, property1, property2, sourceLine, sourceFile); - public void Warning(string messageTemplate, object[] args, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = "") + public void Warning(string messageTemplate, object?[] args, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = "") => Write(LogEventLevel.Warning, exception: null, messageTemplate, args, sourceLine, sourceFile); - public void Warning(Exception exception, string messageTemplate, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = "") + public void Warning(Exception? exception, string messageTemplate, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = "") => Write(LogEventLevel.Warning, exception, messageTemplate, NoPropertyValues, sourceLine, sourceFile); - public void Warning(Exception exception, string messageTemplate, T property, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = "") + public void Warning(Exception? exception, string messageTemplate, T property, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = "") => Write(LogEventLevel.Warning, exception, messageTemplate, property, sourceLine, sourceFile); - public void Warning(Exception exception, string messageTemplate, T0 property0, T1 property1, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = "") + public void Warning(Exception? exception, string messageTemplate, T0 property0, T1 property1, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = "") => Write(LogEventLevel.Warning, exception, messageTemplate, property0, property1, sourceLine, sourceFile); - public void Warning(Exception exception, string messageTemplate, T0 property0, T1 property1, T2 property2, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = "") + public void Warning(Exception? exception, string messageTemplate, T0 property0, T1 property1, T2 property2, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = "") => Write(LogEventLevel.Warning, exception, messageTemplate, property0, property1, property2, sourceLine, sourceFile); - public void Warning(Exception exception, string messageTemplate, object[] args, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = "") + public void Warning(Exception? exception, string messageTemplate, object?[] args, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = "") => Write(LogEventLevel.Warning, exception, messageTemplate, args, sourceLine, sourceFile); public void Error(string messageTemplate, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = "") @@ -135,22 +137,22 @@ public void Error(string messageTemplate, T0 property0, T1 property1, [C public void Error(string messageTemplate, T0 property0, T1 property1, T2 property2, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = "") => Write(LogEventLevel.Error, exception: null, messageTemplate, property0, property1, property2, sourceLine, sourceFile); - public void Error(string messageTemplate, object[] args, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = "") + public void Error(string messageTemplate, object?[] args, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = "") => Write(LogEventLevel.Error, exception: null, messageTemplate, args, sourceLine, sourceFile); - public void Error(Exception exception, string messageTemplate, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = "") + public void Error(Exception? exception, string messageTemplate, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = "") => Write(LogEventLevel.Error, exception, messageTemplate, NoPropertyValues, sourceLine, sourceFile); - public void Error(Exception exception, string messageTemplate, T property, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = "") + public void Error(Exception? exception, string messageTemplate, T property, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = "") => Write(LogEventLevel.Error, exception, messageTemplate, property, sourceLine, sourceFile); - public void Error(Exception exception, string messageTemplate, T0 property0, T1 property1, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = "") + public void Error(Exception? exception, string messageTemplate, T0 property0, T1 property1, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = "") => Write(LogEventLevel.Error, exception, messageTemplate, property0, property1, sourceLine, sourceFile); - public void Error(Exception exception, string messageTemplate, T0 property0, T1 property1, T2 property2, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = "") + public void Error(Exception? exception, string messageTemplate, T0 property0, T1 property1, T2 property2, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = "") => Write(LogEventLevel.Error, exception, messageTemplate, property0, property1, property2, sourceLine, sourceFile); - public void Error(Exception exception, string messageTemplate, object[] args, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = "") + public void Error(Exception? exception, string messageTemplate, object?[] args, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = "") => Write(LogEventLevel.Error, exception, messageTemplate, args, sourceLine, sourceFile); public void CloseAndFlush() @@ -160,43 +162,45 @@ public void CloseAndFlush() (logger as IDisposable)?.Dispose(); } - private void Write(LogEventLevel level, Exception exception, string messageTemplate, T property, int sourceLine, string sourceFile) +#pragma warning disable SA1010 // Opening square bracket should not be preceded by a space + private void Write(LogEventLevel level, Exception? exception, string messageTemplate, T property, int sourceLine, string sourceFile) { if (_logger.IsEnabled(level)) { // Avoid boxing + array allocation if disabled - WriteIfNotRateLimited(level, exception, messageTemplate, new object[] { property }, sourceLine, sourceFile); + WriteIfNotRateLimited(level, exception, messageTemplate, [property], sourceLine, sourceFile); } } - private void Write(LogEventLevel level, Exception exception, string messageTemplate, T0 property0, T1 property1, int sourceLine, string sourceFile) + private void Write(LogEventLevel level, Exception? exception, string messageTemplate, T0 property0, T1 property1, int sourceLine, string sourceFile) { if (_logger.IsEnabled(level)) { // Avoid boxing + array allocation if disabled - WriteIfNotRateLimited(level, exception, messageTemplate, new object[] { property0, property1 }, sourceLine, sourceFile); + WriteIfNotRateLimited(level, exception, messageTemplate, [property0, property1], sourceLine, sourceFile); } } - private void Write(LogEventLevel level, Exception exception, string messageTemplate, T0 property0, T1 property1, T2 property2, int sourceLine, string sourceFile) + private void Write(LogEventLevel level, Exception? exception, string messageTemplate, T0 property0, T1 property1, T2 property2, int sourceLine, string sourceFile) { if (_logger.IsEnabled(level)) { // Avoid boxing + array allocation if disabled - WriteIfNotRateLimited(level, exception, messageTemplate, new object[] { property0, property1, property2 }, sourceLine, sourceFile); + WriteIfNotRateLimited(level, exception, messageTemplate, [property0, property1, property2], sourceLine, sourceFile); } } - private void Write(LogEventLevel level, Exception exception, string messageTemplate, T0 property0, T1 property1, T2 property2, T3 property3, int sourceLine, string sourceFile) + private void Write(LogEventLevel level, Exception? exception, string messageTemplate, T0 property0, T1 property1, T2 property2, T3 property3, int sourceLine, string sourceFile) { if (_logger.IsEnabled(level)) { // Avoid boxing + array allocation if disabled - WriteIfNotRateLimited(level, exception, messageTemplate, new object[] { property0, property1, property2, property3 }, sourceLine, sourceFile); + WriteIfNotRateLimited(level, exception, messageTemplate, [property0, property1, property2, property3], sourceLine, sourceFile); } } +#pragma warning restore SA1010 - private void Write(LogEventLevel level, Exception exception, string messageTemplate, object[] args, int sourceLine, string sourceFile) + private void Write(LogEventLevel level, Exception? exception, string messageTemplate, object?[] args, int sourceLine, string sourceFile) { if (_logger.IsEnabled(level)) { @@ -205,7 +209,7 @@ private void Write(LogEventLevel level, Exception exception, string messageTempl } } - private void WriteIfNotRateLimited(LogEventLevel level, Exception exception, string messageTemplate, object[] args, int sourceLine, string sourceFile) + private void WriteIfNotRateLimited(LogEventLevel level, Exception? exception, string messageTemplate, object?[] args, int sourceLine, string sourceFile) { try { diff --git a/tracer/src/Datadog.Trace/Logging/Internal/IDatadogLogger.cs b/tracer/src/Datadog.Trace/Logging/Internal/IDatadogLogger.cs index f8195039bf93..502f5a67db7a 100644 --- a/tracer/src/Datadog.Trace/Logging/Internal/IDatadogLogger.cs +++ b/tracer/src/Datadog.Trace/Logging/Internal/IDatadogLogger.cs @@ -3,6 +3,8 @@ // This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. // +#nullable enable + using System; using System.Runtime.CompilerServices; using Datadog.Trace.Vendors.Serilog.Events; @@ -23,17 +25,17 @@ internal interface IDatadogLogger void Debug(string messageTemplate, T0 property0, T1 property1, T2 property2, T3 property3, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = ""); - void Debug(string messageTemplate, object[] args, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = ""); + void Debug(string messageTemplate, object?[] args, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = ""); - void Debug(Exception exception, string messageTemplate, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = ""); + void Debug(Exception? exception, string messageTemplate, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = ""); - void Debug(Exception exception, string messageTemplate, T property, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = ""); + void Debug(Exception? exception, string messageTemplate, T property, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = ""); - void Debug(Exception exception, string messageTemplate, T0 property0, T1 property1, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = ""); + void Debug(Exception? exception, string messageTemplate, T0 property0, T1 property1, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = ""); - void Debug(Exception exception, string messageTemplate, T0 property0, T1 property1, T2 property2, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = ""); + void Debug(Exception? exception, string messageTemplate, T0 property0, T1 property1, T2 property2, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = ""); - void Debug(Exception exception, string messageTemplate, object[] args, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = ""); + void Debug(Exception? exception, string messageTemplate, object?[] args, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = ""); void Information(string messageTemplate, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = ""); @@ -43,17 +45,17 @@ internal interface IDatadogLogger void Information(string messageTemplate, T0 property0, T1 property1, T2 property2, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = ""); - void Information(string messageTemplate, object[] args, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = ""); + void Information(string messageTemplate, object?[] args, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = ""); - void Information(Exception exception, string messageTemplate, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = ""); + void Information(Exception? exception, string messageTemplate, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = ""); - void Information(Exception exception, string messageTemplate, T property, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = ""); + void Information(Exception? exception, string messageTemplate, T property, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = ""); - void Information(Exception exception, string messageTemplate, T0 property0, T1 property1, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = ""); + void Information(Exception? exception, string messageTemplate, T0 property0, T1 property1, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = ""); - void Information(Exception exception, string messageTemplate, T0 property0, T1 property1, T2 property2, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = ""); + void Information(Exception? exception, string messageTemplate, T0 property0, T1 property1, T2 property2, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = ""); - void Information(Exception exception, string messageTemplate, object[] args, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = ""); + void Information(Exception? exception, string messageTemplate, object?[] args, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = ""); void Warning(string messageTemplate, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = ""); @@ -63,17 +65,17 @@ internal interface IDatadogLogger void Warning(string messageTemplate, T0 property0, T1 property1, T2 property2, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = ""); - void Warning(string messageTemplate, object[] args, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = ""); + void Warning(string messageTemplate, object?[] args, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = ""); - void Warning(Exception exception, string messageTemplate, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = ""); + void Warning(Exception? exception, string messageTemplate, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = ""); - void Warning(Exception exception, string messageTemplate, T property, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = ""); + void Warning(Exception? exception, string messageTemplate, T property, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = ""); - void Warning(Exception exception, string messageTemplate, T0 property0, T1 property1, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = ""); + void Warning(Exception? exception, string messageTemplate, T0 property0, T1 property1, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = ""); - void Warning(Exception exception, string messageTemplate, T0 property0, T1 property1, T2 property2, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = ""); + void Warning(Exception? exception, string messageTemplate, T0 property0, T1 property1, T2 property2, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = ""); - void Warning(Exception exception, string messageTemplate, object[] args, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = ""); + void Warning(Exception? exception, string messageTemplate, object?[] args, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = ""); void Error(string messageTemplate, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = ""); @@ -83,17 +85,17 @@ internal interface IDatadogLogger void Error(string messageTemplate, T0 property0, T1 property1, T2 property2, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = ""); - void Error(string messageTemplate, object[] args, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = ""); + void Error(string messageTemplate, object?[] args, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = ""); - void Error(Exception exception, string messageTemplate, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = ""); + void Error(Exception? exception, string messageTemplate, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = ""); - void Error(Exception exception, string messageTemplate, T property, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = ""); + void Error(Exception? exception, string messageTemplate, T property, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = ""); - void Error(Exception exception, string messageTemplate, T0 property0, T1 property1, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = ""); + void Error(Exception? exception, string messageTemplate, T0 property0, T1 property1, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = ""); - void Error(Exception exception, string messageTemplate, T0 property0, T1 property1, T2 property2, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = ""); + void Error(Exception? exception, string messageTemplate, T0 property0, T1 property1, T2 property2, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = ""); - void Error(Exception exception, string messageTemplate, object[] args, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = ""); + void Error(Exception? exception, string messageTemplate, object?[] args, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = ""); void CloseAndFlush(); } diff --git a/tracer/src/Datadog.Trace/Logging/Internal/ILogRateLimiter.cs b/tracer/src/Datadog.Trace/Logging/Internal/ILogRateLimiter.cs index 065e01f0ddfa..a47cb0953a56 100644 --- a/tracer/src/Datadog.Trace/Logging/Internal/ILogRateLimiter.cs +++ b/tracer/src/Datadog.Trace/Logging/Internal/ILogRateLimiter.cs @@ -3,6 +3,8 @@ // This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. // +#nullable enable + namespace Datadog.Trace.Logging { internal interface ILogRateLimiter diff --git a/tracer/src/Datadog.Trace/Logging/Internal/LogRateLimiter.cs b/tracer/src/Datadog.Trace/Logging/Internal/LogRateLimiter.cs index 2388264402f8..aa5692fea0c0 100644 --- a/tracer/src/Datadog.Trace/Logging/Internal/LogRateLimiter.cs +++ b/tracer/src/Datadog.Trace/Logging/Internal/LogRateLimiter.cs @@ -3,6 +3,8 @@ // This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. // +#nullable enable + using System; using System.Collections.Concurrent; @@ -13,8 +15,7 @@ namespace Datadog.Trace.Logging internal class LogRateLimiter : ILogRateLimiter { private readonly int _secondsBetweenLogs; - private readonly ConcurrentDictionary _buckets - = new ConcurrentDictionary(); + private readonly ConcurrentDictionary _buckets = new(); public LogRateLimiter(int secondsBetweenLogs) { @@ -49,7 +50,7 @@ public bool ShouldLog(string filePath, int lineNumber, out uint skipCount) var newLogInfo = _buckets.AddOrUpdate( key, new LogRateBucketInfo(currentTimeBucket, skipCount: 0, 0), - (key, prev) => GetUpdatedLimitInfo(prev, currentTimeBucket)); + (_, prev) => GetUpdatedLimitInfo(prev, currentTimeBucket)); skipCount = newLogInfo.PreviousSkipCount; return newLogInfo.SkipCount == 0; @@ -90,7 +91,7 @@ public LogRateBucketKey(string filePath, int lineNo) LineNo = lineNo; } - public override bool Equals(object obj) + public override bool Equals(object? obj) { return obj is LogRateBucketKey key && FilePath == key.FilePath && diff --git a/tracer/src/Datadog.Trace/Logging/Internal/NullLogRateLimiter.cs b/tracer/src/Datadog.Trace/Logging/Internal/NullLogRateLimiter.cs index d10193dd67f8..310273fb3168 100644 --- a/tracer/src/Datadog.Trace/Logging/Internal/NullLogRateLimiter.cs +++ b/tracer/src/Datadog.Trace/Logging/Internal/NullLogRateLimiter.cs @@ -3,6 +3,8 @@ // This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. // +#nullable enable + namespace Datadog.Trace.Logging { internal class NullLogRateLimiter : ILogRateLimiter From da22f24c7138d931152acf5e4951d5eafd9ca07f Mon Sep 17 00:00:00 2001 From: Andrew Lock Date: Wed, 20 Dec 2023 13:34:05 +0000 Subject: [PATCH 2/4] Update nullability file --- tracer/missing-nullability-files.csv | 6 ------ 1 file changed, 6 deletions(-) diff --git a/tracer/missing-nullability-files.csv b/tracer/missing-nullability-files.csv index 45665557ea42..7c7e8536bf8d 100644 --- a/tracer/missing-nullability-files.csv +++ b/tracer/missing-nullability-files.csv @@ -433,12 +433,6 @@ src/Datadog.Trace/IAST/Analyzers/UserStringInterop.cs src/Datadog.Trace/IAST/Aspects/DebugAspects.cs src/Datadog.Trace/IAST/Dataflow/AspectFilter.cs src/Datadog.Trace/IAST/Dataflow/AspectType.cs -src/Datadog.Trace/Logging/Internal/DatadogLogging.cs -src/Datadog.Trace/Logging/Internal/DatadogSerilogLogger.cs -src/Datadog.Trace/Logging/Internal/IDatadogLogger.cs -src/Datadog.Trace/Logging/Internal/ILogRateLimiter.cs -src/Datadog.Trace/Logging/Internal/LogRateLimiter.cs -src/Datadog.Trace/Logging/Internal/NullLogRateLimiter.cs src/Datadog.Trace/PDBs/dnlibAdditions/DssSymbolReaderImpl.Additions.cs src/Datadog.Trace/PDBs/dnlibAdditions/PdbReader.Additions.cs src/Datadog.Trace/PDBs/dnlibAdditions/PortablePdbReader.Additions.cs From 610521ab6c177497cbc8578784e0b7e7fca68e47 Mon Sep 17 00:00:00 2001 From: Andrew Lock Date: Wed, 20 Dec 2023 13:32:48 +0000 Subject: [PATCH 3/4] Update codeanalysis packages to the latest Necessary to properly support C#12 Had to disable all the analyzer tracking stuff (so annoying, can't find a good way to turn it off) --- .../Datadog.Trace.SourceGenerators.csproj | 6 ++++-- .../Datadog.Trace.Tools.Analyzers.csproj | 8 +++++--- .../LogAnalyzer/Diagnostics.cs | 20 +++++++++---------- ...atadog.Trace.SourceGenerators.Tests.csproj | 2 +- ...Datadog.Trace.Tools.Analyzers.Tests.csproj | 14 ++++++------- .../CorrectLoggingAbstractionDiagnostic.cs | 2 +- 6 files changed, 28 insertions(+), 24 deletions(-) diff --git a/tracer/src/Datadog.Trace.SourceGenerators/Datadog.Trace.SourceGenerators.csproj b/tracer/src/Datadog.Trace.SourceGenerators/Datadog.Trace.SourceGenerators.csproj index 80e1947fc4f7..fa50c0c91938 100644 --- a/tracer/src/Datadog.Trace.SourceGenerators/Datadog.Trace.SourceGenerators.csproj +++ b/tracer/src/Datadog.Trace.SourceGenerators/Datadog.Trace.SourceGenerators.csproj @@ -6,6 +6,8 @@ true + false + RS2008 @@ -257,8 +259,8 @@ - - + + diff --git a/tracer/src/Datadog.Trace.Tools.Analyzers/Datadog.Trace.Tools.Analyzers.csproj b/tracer/src/Datadog.Trace.Tools.Analyzers/Datadog.Trace.Tools.Analyzers.csproj index 1a168f82528d..c1906dbfbe82 100644 --- a/tracer/src/Datadog.Trace.Tools.Analyzers/Datadog.Trace.Tools.Analyzers.csproj +++ b/tracer/src/Datadog.Trace.Tools.Analyzers/Datadog.Trace.Tools.Analyzers.csproj @@ -3,12 +3,14 @@ netstandard2.0 false + false + RS2008 - - - + + + diff --git a/tracer/src/Datadog.Trace.Tools.Analyzers/LogAnalyzer/Diagnostics.cs b/tracer/src/Datadog.Trace.Tools.Analyzers/LogAnalyzer/Diagnostics.cs index d81eb446a1b8..bb7c96659e22 100644 --- a/tracer/src/Datadog.Trace.Tools.Analyzers/LogAnalyzer/Diagnostics.cs +++ b/tracer/src/Datadog.Trace.Tools.Analyzers/LogAnalyzer/Diagnostics.cs @@ -65,7 +65,7 @@ public class Diagnostics "CodeQuality", defaultSeverity: DiagnosticSeverity.Error, isEnabledByDefault: true, - description: "Exceptions should be passed in the Exception Parameter"); + description: "Exceptions should be passed in the Exception Parameter."); internal static readonly DiagnosticDescriptor TemplateRule = new( TemplateDiagnosticId, @@ -74,7 +74,7 @@ public class Diagnostics category: "CodeQuality", defaultSeverity: DiagnosticSeverity.Error, isEnabledByDefault: true, - description: "Checks for errors in the MessageTemplate"); + description: "Checks for errors in the MessageTemplate."); internal static readonly DiagnosticDescriptor PropertyBindingRule = new( PropertyBindingDiagnosticId, @@ -83,7 +83,7 @@ public class Diagnostics category: "CodeQuality", defaultSeverity: DiagnosticSeverity.Error, isEnabledByDefault: true, - description: "Checks whether properties and arguments match up"); + description: "Checks whether properties and arguments match up."); internal static readonly DiagnosticDescriptor ConstantMessageTemplateRule = new( ConstantMessageTemplateDiagnosticId, @@ -92,7 +92,7 @@ public class Diagnostics category: "CodeQuality", defaultSeverity: DiagnosticSeverity.Error, isEnabledByDefault: true, - description: "MessageTemplate must be a constant value to ensure caching and avoid interpolation issues"); + description: "MessageTemplate must be a constant value to ensure caching and avoid interpolation issues."); internal static readonly DiagnosticDescriptor UniquePropertyNameRule = new( UniquePropertyNameDiagnosticId, @@ -101,7 +101,7 @@ public class Diagnostics category: "CodeQuality", defaultSeverity: DiagnosticSeverity.Error, isEnabledByDefault: true, - description: "All property names in a MessageTemplate must be unique"); + description: "All property names in a MessageTemplate must be unique."); internal static readonly DiagnosticDescriptor PascalPropertyNameRule = new( PascalPropertyNameDiagnosticId, @@ -110,7 +110,7 @@ public class Diagnostics category: "CodeQuality", defaultSeverity: DiagnosticSeverity.Warning, isEnabledByDefault: true, - description: "Property names in a MessageTemplates should be Pascal Case for consistency"); + description: "Property names in a MessageTemplates should be Pascal Case for consistency."); internal static readonly DiagnosticDescriptor DestructureAnonymousObjectsRule = new( DestructureAnonymousObjectsDiagnosticId, @@ -119,7 +119,7 @@ public class Diagnostics category: "CodeQuality", defaultSeverity: DiagnosticSeverity.Error, isEnabledByDefault: true, - description: "Anonymous objects should use the '@' hint to ensure they are destructed"); + description: "Anonymous objects should use the '@' hint to ensure they are destructed."); internal static readonly DiagnosticDescriptor UseCorrectContextualLoggerRule = new( UseCorrectContextualLoggerDiagnosticId, @@ -128,14 +128,14 @@ public class Diagnostics category: "CodeQuality", defaultSeverity: DiagnosticSeverity.Warning, isEnabledByDefault: true, - description: "Logger instances should use the current class for context"); + description: "Logger instances should use the current class for context."); internal static readonly DiagnosticDescriptor UseDatadogLoggerRule = new( UseDatadogLoggerDiagnosticId, title: "Incorrect logger type", - messageFormat: "Incorrect use of Serilog ILogger. Use IDatadogLogger instead", + messageFormat: "Incorrect use of Serilog ILogger. Use IDatadogLogger instead.", category: "CodeQuality", defaultSeverity: DiagnosticSeverity.Warning, isEnabledByDefault: true, - description: "You should use the IDatadogLogger wrapper for logging"); + description: "You should use the IDatadogLogger wrapper for logging."); } diff --git a/tracer/test/Datadog.Trace.SourceGenerators.Tests/Datadog.Trace.SourceGenerators.Tests.csproj b/tracer/test/Datadog.Trace.SourceGenerators.Tests/Datadog.Trace.SourceGenerators.Tests.csproj index 344d9bbab30c..4381fcac3b6c 100644 --- a/tracer/test/Datadog.Trace.SourceGenerators.Tests/Datadog.Trace.SourceGenerators.Tests.csproj +++ b/tracer/test/Datadog.Trace.SourceGenerators.Tests/Datadog.Trace.SourceGenerators.Tests.csproj @@ -6,7 +6,7 @@ - + diff --git a/tracer/test/Datadog.Trace.Tools.Analyzers.Tests/Datadog.Trace.Tools.Analyzers.Tests.csproj b/tracer/test/Datadog.Trace.Tools.Analyzers.Tests/Datadog.Trace.Tools.Analyzers.Tests.csproj index 9404ee31dc73..0a3f62f80816 100644 --- a/tracer/test/Datadog.Trace.Tools.Analyzers.Tests/Datadog.Trace.Tools.Analyzers.Tests.csproj +++ b/tracer/test/Datadog.Trace.Tools.Analyzers.Tests/Datadog.Trace.Tools.Analyzers.Tests.csproj @@ -7,13 +7,13 @@ - - - - - - - + + + + + + + diff --git a/tracer/test/Datadog.Trace.Tools.Analyzers.Tests/LogAnalyzer/CorrectLoggingAbstractionDiagnostic.cs b/tracer/test/Datadog.Trace.Tools.Analyzers.Tests/LogAnalyzer/CorrectLoggingAbstractionDiagnostic.cs index 3a85cf7424bf..89628cb56154 100644 --- a/tracer/test/Datadog.Trace.Tools.Analyzers.Tests/LogAnalyzer/CorrectLoggingAbstractionDiagnostic.cs +++ b/tracer/test/Datadog.Trace.Tools.Analyzers.Tests/LogAnalyzer/CorrectLoggingAbstractionDiagnostic.cs @@ -81,7 +81,7 @@ public void Main() var expected = new DiagnosticResult(DiagnosticId, Severity) .WithLocation(0) - .WithMessage("Incorrect use of Serilog ILogger. Use IDatadogLogger instead"); + .WithMessage("Incorrect use of Serilog ILogger. Use IDatadogLogger instead."); await Verifier.VerifyAnalyzerAsync(src, expected); } } From d6aaead707692c6ce6f3f66cde60ab84c6670c45 Mon Sep 17 00:00:00 2001 From: Andrew Lock Date: Wed, 20 Dec 2023 13:33:21 +0000 Subject: [PATCH 4/4] Update the log analyzer and tests to support the new interfaces --- .../LogAnalyzer/LogAnalyzer.cs | 3 +- .../LogAnalyzer/Helpers.cs | 50 ++++++++++--------- .../LogAnalyzer/PropertyDiagnosticTests.cs | 46 +++++++++++++++++ 3 files changed, 74 insertions(+), 25 deletions(-) diff --git a/tracer/src/Datadog.Trace.Tools.Analyzers/LogAnalyzer/LogAnalyzer.cs b/tracer/src/Datadog.Trace.Tools.Analyzers/LogAnalyzer/LogAnalyzer.cs index 39cc71f50084..983abdf050c1 100644 --- a/tracer/src/Datadog.Trace.Tools.Analyzers/LogAnalyzer/LogAnalyzer.cs +++ b/tracer/src/Datadog.Trace.Tools.Analyzers/LogAnalyzer/LogAnalyzer.cs @@ -155,7 +155,8 @@ private static void AnalyzeSymbol(SyntaxNodeAnalysisContext context) var nextParameterIndex = messageTemplateArgumentIndex + 1; if ((invocationArguments.Count == nextParameterIndex + 1) && method.Parameters.Length > nextParameterIndex - && method.Parameters[nextParameterIndex].Type.ToString() == "object[]") + && (method.Parameters[nextParameterIndex].Type.ToString() == "object[]" + || method.Parameters[nextParameterIndex].Type.ToString() == "object?[]")) { // we're in the object[] version of the log message, if (invocationArguments[nextParameterIndex].Expression is ArrayCreationExpressionSyntax { Initializer: { } initializer }) diff --git a/tracer/test/Datadog.Trace.Tools.Analyzers.Tests/LogAnalyzer/Helpers.cs b/tracer/test/Datadog.Trace.Tools.Analyzers.Tests/LogAnalyzer/Helpers.cs index 40aff6a8c57e..04ae5ee53b76 100644 --- a/tracer/test/Datadog.Trace.Tools.Analyzers.Tests/LogAnalyzer/Helpers.cs +++ b/tracer/test/Datadog.Trace.Tools.Analyzers.Tests/LogAnalyzer/Helpers.cs @@ -19,6 +19,8 @@ public static class Helpers public static string LoggerDefinitions { get; } = """ + #nullable enable + namespace Datadog.Trace.Logging { using System; @@ -38,42 +40,42 @@ internal interface IDatadogLogger void Debug(string messageTemplate, T0 property0, T1 property1, int sourceLine = 0, string sourceFile = ""); void Debug(string messageTemplate, T0 property0, T1 property1, T2 property2, int sourceLine = 0, string sourceFile = ""); void Debug(string messageTemplate, T0 property0, T1 property1, T2 property2, T3 property3, int sourceLine = 0, string sourceFile = ""); - void Debug(string messageTemplate, object[] args, int sourceLine = 0, string sourceFile = ""); - void Debug(Exception exception, string messageTemplate, int sourceLine = 0, string sourceFile = ""); - void Debug(Exception exception, string messageTemplate, T property, int sourceLine = 0, string sourceFile = ""); - void Debug(Exception exception, string messageTemplate, T0 property0, T1 property1, int sourceLine = 0, string sourceFile = ""); - void Debug(Exception exception, string messageTemplate, T0 property0, T1 property1, T2 property2, int sourceLine = 0, string sourceFile = ""); - void Debug(Exception exception, string messageTemplate, object[] args, int sourceLine = 0, string sourceFile = ""); + void Debug(string messageTemplate, object?[] args, int sourceLine = 0, string sourceFile = ""); + void Debug(Exception? exception, string messageTemplate, int sourceLine = 0, string sourceFile = ""); + void Debug(Exception? exception, string messageTemplate, T property, int sourceLine = 0, string sourceFile = ""); + void Debug(Exception? exception, string messageTemplate, T0 property0, T1 property1, int sourceLine = 0, string sourceFile = ""); + void Debug(Exception? exception, string messageTemplate, T0 property0, T1 property1, T2 property2, int sourceLine = 0, string sourceFile = ""); + void Debug(Exception? exception, string messageTemplate, object?[] args, int sourceLine = 0, string sourceFile = ""); void Information(string messageTemplate, int sourceLine = 0, string sourceFile = ""); void Information(string messageTemplate, T property, int sourceLine = 0, string sourceFile = ""); void Information(string messageTemplate, T0 property0, T1 property1, int sourceLine = 0, string sourceFile = ""); void Information(string messageTemplate, T0 property0, T1 property1, T2 property2, int sourceLine = 0, string sourceFile = ""); - void Information(string messageTemplate, object[] args, int sourceLine = 0, string sourceFile = ""); - void Information(Exception exception, string messageTemplate, int sourceLine = 0, string sourceFile = ""); - void Information(Exception exception, string messageTemplate, T property, int sourceLine = 0, string sourceFile = ""); - void Information(Exception exception, string messageTemplate, T0 property0, T1 property1, int sourceLine = 0, string sourceFile = ""); - void Information(Exception exception, string messageTemplate, T0 property0, T1 property1, T2 property2, int sourceLine = 0, string sourceFile = ""); - void Information(Exception exception, string messageTemplate, object[] args, int sourceLine = 0, string sourceFile = ""); + void Information(string messageTemplate, object?[] args, int sourceLine = 0, string sourceFile = ""); + void Information(Exception? exception, string messageTemplate, int sourceLine = 0, string sourceFile = ""); + void Information(Exception? exception, string messageTemplate, T property, int sourceLine = 0, string sourceFile = ""); + void Information(Exception? exception, string messageTemplate, T0 property0, T1 property1, int sourceLine = 0, string sourceFile = ""); + void Information(Exception? exception, string messageTemplate, T0 property0, T1 property1, T2 property2, int sourceLine = 0, string sourceFile = ""); + void Information(Exception? exception, string messageTemplate, object?[] args, int sourceLine = 0, string sourceFile = ""); void Warning(string messageTemplate, int sourceLine = 0, string sourceFile = ""); void Warning(string messageTemplate, T property, int sourceLine = 0, string sourceFile = ""); void Warning(string messageTemplate, T0 property0, T1 property1, int sourceLine = 0, string sourceFile = ""); void Warning(string messageTemplate, T0 property0, T1 property1, T2 property2, int sourceLine = 0, string sourceFile = ""); - void Warning(string messageTemplate, object[] args, int sourceLine = 0, string sourceFile = ""); - void Warning(Exception exception, string messageTemplate, int sourceLine = 0, string sourceFile = ""); - void Warning(Exception exception, string messageTemplate, T property, int sourceLine = 0, string sourceFile = ""); - void Warning(Exception exception, string messageTemplate, T0 property0, T1 property1, int sourceLine = 0, string sourceFile = ""); - void Warning(Exception exception, string messageTemplate, T0 property0, T1 property1, T2 property2, int sourceLine = 0, string sourceFile = ""); - void Warning(Exception exception, string messageTemplate, object[] args, int sourceLine = 0, string sourceFile = ""); + void Warning(string messageTemplate, object?[] args, int sourceLine = 0, string sourceFile = ""); + void Warning(Exception? exception, string messageTemplate, int sourceLine = 0, string sourceFile = ""); + void Warning(Exception? exception, string messageTemplate, T property, int sourceLine = 0, string sourceFile = ""); + void Warning(Exception? exception, string messageTemplate, T0 property0, T1 property1, int sourceLine = 0, string sourceFile = ""); + void Warning(Exception? exception, string messageTemplate, T0 property0, T1 property1, T2 property2, int sourceLine = 0, string sourceFile = ""); + void Warning(Exception? exception, string messageTemplate, object?[] args, int sourceLine = 0, string sourceFile = ""); void Error(string messageTemplate, int sourceLine = 0, string sourceFile = ""); void Error(string messageTemplate, T property, int sourceLine = 0, string sourceFile = ""); void Error(string messageTemplate, T0 property0, T1 property1, int sourceLine = 0, string sourceFile = ""); void Error(string messageTemplate, T0 property0, T1 property1, T2 property2, int sourceLine = 0, string sourceFile = ""); - void Error(string messageTemplate, object[] args, int sourceLine = 0, string sourceFile = ""); - void Error(Exception exception, string messageTemplate, int sourceLine = 0, string sourceFile = ""); - void Error(Exception exception, string messageTemplate, T property, int sourceLine = 0, string sourceFile = ""); - void Error(Exception exception, string messageTemplate, T0 property0, T1 property1, int sourceLine = 0, string sourceFile = ""); - void Error(Exception exception, string messageTemplate, T0 property0, T1 property1, T2 property2, int sourceLine = 0, string sourceFile = ""); - void Error(Exception exception, string messageTemplate, object[] args, int sourceLine = 0, string sourceFile = ""); + void Error(string messageTemplate, object?[] args, int sourceLine = 0, string sourceFile = ""); + void Error(Exception? exception, string messageTemplate, int sourceLine = 0, string sourceFile = ""); + void Error(Exception? exception, string messageTemplate, T property, int sourceLine = 0, string sourceFile = ""); + void Error(Exception? exception, string messageTemplate, T0 property0, T1 property1, int sourceLine = 0, string sourceFile = ""); + void Error(Exception? exception, string messageTemplate, T0 property0, T1 property1, T2 property2, int sourceLine = 0, string sourceFile = ""); + void Error(Exception? exception, string messageTemplate, object?[] args, int sourceLine = 0, string sourceFile = ""); void CloseAndFlush(); } } diff --git a/tracer/test/Datadog.Trace.Tools.Analyzers.Tests/LogAnalyzer/PropertyDiagnosticTests.cs b/tracer/test/Datadog.Trace.Tools.Analyzers.Tests/LogAnalyzer/PropertyDiagnosticTests.cs index 419f2c034962..2026c9cf2346 100644 --- a/tracer/test/Datadog.Trace.Tools.Analyzers.Tests/LogAnalyzer/PropertyDiagnosticTests.cs +++ b/tracer/test/Datadog.Trace.Tools.Analyzers.Tests/LogAnalyzer/PropertyDiagnosticTests.cs @@ -66,6 +66,52 @@ public static void Test() await Verifier.VerifyAnalyzerAsync(src); } + [Theory] + [MemberData(nameof(Helpers.LogMethods), MemberType = typeof(Helpers))] + public async Task ShouldNotFlag_MatchingPropertiesAndArgsWhenUsingNullableArray(string logMethod) + { + var src = $$""" + #nullable enable + using Datadog.Trace.Logging; + + {{Helpers.LoggerDefinitions}} + + class TypeName + { + private static IDatadogLogger Log = null; + public static void Test() + { + Log.{{logMethod}}("Hello {Tester1} {Tester2}", new object?[] {"tester1", "tester2"}); + } + } + """; + + await Verifier.VerifyAnalyzerAsync(src); + } + + [Theory] + [MemberData(nameof(Helpers.LogMethods), MemberType = typeof(Helpers))] + public async Task ShouldNotFlag_MatchingPropertiesAndArgsWhenUsingCollectionInitializer(string logMethod) + { + var src = $$""" + #nullable enable + using Datadog.Trace.Logging; + + {{Helpers.LoggerDefinitions}} + + class TypeName + { + private static IDatadogLogger Log = null; + public static void Test() + { + Log.{{logMethod}}("Hello {Tester1} {Tester2}", ["tester1", "tester2"]); + } + } + """; + + await Verifier.VerifyAnalyzerAsync(src); + } + [Theory] [MemberData(nameof(Helpers.LogMethods), MemberType = typeof(Helpers))] public async Task ShouldNotFlag_MatchingPositionalPropertiesAndArgs(string logMethod)