Skip to content

Commit 890ab1f

Browse files
committed
Back-port #1411 to 6.x
Fixes #1410
1 parent 51c602d commit 890ab1f

File tree

6 files changed

+37
-31
lines changed

6 files changed

+37
-31
lines changed

build.bat

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
@ECHO OFF
22
set DOTNET_CLI_TELEMETRY_OPTOUT=1
3-
dotnet restore --verbosity=normal .\RabbitMQDotNetClient.sln
4-
dotnet run --verbosity=normal --framework net6.0 --project .\projects\Apigen\Apigen.csproj --apiName:AMQP_0_9_1 .\projects\specs\amqp0-9-1.stripped.xml .\gensrc\autogenerated-api-0-9-1.cs
5-
dotnet build --verbosity=normal .\RabbitMQDotNetClient.sln
3+
dotnet restore .\RabbitMQDotNetClient.sln
4+
dotnet run --framework net6.0 --project .\projects\Apigen\Apigen.csproj --apiName:AMQP_0_9_1 .\projects\specs\amqp0-9-1.stripped.xml .\gensrc\autogenerated-api-0-9-1.cs
5+
dotnet build .\RabbitMQDotNetClient.sln

projects/RabbitMQ.Client/RabbitMQ.Client.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
66
<NoWarn>$(NoWarn);CS1591</NoWarn>
77
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
8+
<EnableTrimAnalyzer Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net6.0'))">true</EnableTrimAnalyzer>
9+
<IsTrimmable Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net6.0'))">true</IsTrimmable>
810
<AssemblyTitle>RabbitMQ Client Library for .NET</AssemblyTitle>
911
<Authors>VMware</Authors>
1012
<Company>VMware, Inc. or its affiliates.</Company>

projects/RabbitMQ.Client/client/api/ICredentialsRefresher.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737
namespace RabbitMQ.Client
3838
{
39-
public delegate void NotifyCredentialRefreshed(bool succesfully);
39+
public delegate void NotifyCredentialRefreshed(bool successfully);
4040

4141
public interface ICredentialsRefresher
4242
{
@@ -54,10 +54,16 @@ public class TimerBasedCredentialRefresherEventSource : EventSource
5454
[Event(2)]
5555
public void Unregistered(string name) => WriteEvent(2, "UnRegistered", name);
5656
[Event(3)]
57+
#if NET6_0_OR_GREATER
58+
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "Parameters to this method are primitive and are trimmer safe")]
59+
#endif
5760
public void ScheduledTimer(string name, double interval) => WriteEvent(3, "ScheduledTimer", name, interval);
5861
[Event(4)]
5962
public void TriggeredTimer(string name) => WriteEvent(4, "TriggeredTimer", name);
6063
[Event(5)]
64+
#if NET6_0_OR_GREATER
65+
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "Parameters to this method are primitive and are trimmer safe")]
66+
#endif
6167
public void RefreshedCredentials(string name, bool succesfully) => WriteEvent(5, "RefreshedCredentials", name, succesfully);
6268
[Event(6)]
6369
public void AlreadyRegistered(string name) => WriteEvent(6, "AlreadyRegistered", name);

projects/RabbitMQ.Client/client/logging/RabbitMqClientEventSource.cs

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -34,64 +34,57 @@
3434

3535
namespace RabbitMQ.Client.Logging
3636
{
37-
[EventSource(Name="rabbitmq-dotnet-client")]
37+
[EventSource(Name = "rabbitmq-dotnet-client")]
3838
public sealed class RabbitMqClientEventSource : EventSource
3939
{
4040
public class Keywords
4141
{
4242
public const EventKeywords Log = (EventKeywords)1;
4343
}
44-
#if NET452
45-
public RabbitMqClientEventSource() : base()
46-
{
4744

48-
}
49-
#else
5045
public RabbitMqClientEventSource() : base(EventSourceSettings.EtwSelfDescribingEventFormat)
5146
{
5247
}
53-
#endif
5448

55-
public static RabbitMqClientEventSource Log = new RabbitMqClientEventSource ();
49+
public static RabbitMqClientEventSource Log = new RabbitMqClientEventSource();
5650

5751
[Event(1, Message = "INFO", Keywords = Keywords.Log, Level = EventLevel.Informational)]
5852
public void Info(string message)
5953
{
60-
if(IsEnabled())
54+
if (IsEnabled())
6155
WriteEvent(1, message);
6256
}
6357

6458
[Event(2, Message = "WARN", Keywords = Keywords.Log, Level = EventLevel.Warning)]
6559
public void Warn(string message)
6660
{
67-
if(IsEnabled())
61+
if (IsEnabled())
6862
WriteEvent(2, message);
6963
}
70-
#if NET452
64+
7165
[Event(3, Message = "ERROR", Keywords = Keywords.Log, Level = EventLevel.Error)]
72-
public void Error(string message, string detail)
66+
public void Error(string message, RabbitMqExceptionDetail ex)
7367
{
74-
if(IsEnabled())
75-
this.WriteEvent(3, message, detail);
76-
}
68+
if (IsEnabled())
69+
{
70+
#if NET6_0_OR_GREATER
71+
WriteExceptionEvent(message, ex);
72+
73+
[UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "The properties are preserved with the DynamicallyAccessedMembers attribute.")]
74+
void WriteExceptionEvent<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)] T>(string message, T ex)
75+
{
76+
WriteEvent(3, message, ex);
77+
}
7778
#else
78-
[Event(3, Message = "ERROR", Keywords = Keywords.Log, Level = EventLevel.Error)]
79-
public void Error(string message, RabbitMqExceptionDetail ex)
80-
{
81-
if(IsEnabled())
8279
WriteEvent(3, message, ex);
83-
}
8480
#endif
81+
}
82+
}
8583

8684
[NonEvent]
8785
public void Error(string message, Exception ex)
8886
{
89-
90-
#if NET452
91-
Error(message, ex.ToString());
92-
#else
9387
Error(message, new RabbitMqExceptionDetail(ex));
94-
#endif
9588
}
9689
}
9790
}

projects/RabbitMQ.Client/client/logging/RabbitMqExceptionDetail.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public RabbitMqExceptionDetail(Exception ex)
4646
Type = ex.GetType().FullName;
4747
Message = ex.Message;
4848
StackTrace = ex.StackTrace;
49-
if(ex.InnerException != null)
49+
if (ex.InnerException != null)
5050
{
5151
InnerException = ex.InnerException.ToString();
5252
}
@@ -63,6 +63,11 @@ public RabbitMqExceptionDetail(IDictionary<string, object> ex)
6363
}
6464
}
6565

66+
67+
// NOTE: This type is used to write EventData in RabbitMqClientEventSource.Error. To make it trim-compatible, these properties are preserved
68+
// in RabbitMqClientEventSource. If RabbitMqExceptionDetail gets a property that is a complex type, we need to ensure the nested properties are
69+
// preserved as well.
70+
6671
public string Type { get; private set; }
6772
public string Message { get; private set; }
6873
public string StackTrace { get; private set; }

projects/Unit/APIApproval.Approve.verified.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ namespace RabbitMQ.Client
571571
System.Threading.Tasks.Task ConnectAsync(string host, int port);
572572
System.Net.Sockets.NetworkStream GetStream();
573573
}
574-
public delegate void NotifyCredentialRefreshed(bool succesfully);
574+
public delegate void NotifyCredentialRefreshed(bool successfully);
575575
public class PlainMechanism : RabbitMQ.Client.IAuthMechanism
576576
{
577577
public PlainMechanism() { }

0 commit comments

Comments
 (0)