Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Back-port #1411 to 6.x #1457

Merged
merged 1 commit into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions build.bat
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@ECHO OFF
set DOTNET_CLI_TELEMETRY_OPTOUT=1
dotnet restore --verbosity=normal .\RabbitMQDotNetClient.sln
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
dotnet build --verbosity=normal .\RabbitMQDotNetClient.sln
dotnet restore .\RabbitMQDotNetClient.sln
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
dotnet build .\RabbitMQDotNetClient.sln
2 changes: 2 additions & 0 deletions projects/RabbitMQ.Client/RabbitMQ.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
<NoWarn>$(NoWarn);CS1591</NoWarn>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<EnableTrimAnalyzer Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net6.0'))">true</EnableTrimAnalyzer>
<IsTrimmable Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net6.0'))">true</IsTrimmable>
<AssemblyTitle>RabbitMQ Client Library for .NET</AssemblyTitle>
<Authors>VMware</Authors>
<Company>VMware, Inc. or its affiliates.</Company>
Expand Down
8 changes: 7 additions & 1 deletion projects/RabbitMQ.Client/client/api/ICredentialsRefresher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

namespace RabbitMQ.Client
{
public delegate void NotifyCredentialRefreshed(bool succesfully);
public delegate void NotifyCredentialRefreshed(bool successfully);

public interface ICredentialsRefresher
{
Expand All @@ -54,10 +54,16 @@ public class TimerBasedCredentialRefresherEventSource : EventSource
[Event(2)]
public void Unregistered(string name) => WriteEvent(2, "UnRegistered", name);
[Event(3)]
#if NET6_0_OR_GREATER
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "Parameters to this method are primitive and are trimmer safe")]
#endif
public void ScheduledTimer(string name, double interval) => WriteEvent(3, "ScheduledTimer", name, interval);
[Event(4)]
public void TriggeredTimer(string name) => WriteEvent(4, "TriggeredTimer", name);
[Event(5)]
#if NET6_0_OR_GREATER
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "Parameters to this method are primitive and are trimmer safe")]
#endif
public void RefreshedCredentials(string name, bool succesfully) => WriteEvent(5, "RefreshedCredentials", name, succesfully);
[Event(6)]
public void AlreadyRegistered(string name) => WriteEvent(6, "AlreadyRegistered", name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,64 +34,57 @@

namespace RabbitMQ.Client.Logging
{
[EventSource(Name="rabbitmq-dotnet-client")]
[EventSource(Name = "rabbitmq-dotnet-client")]
public sealed class RabbitMqClientEventSource : EventSource
{
public class Keywords
{
public const EventKeywords Log = (EventKeywords)1;
}
#if NET452
public RabbitMqClientEventSource() : base()
{

}
#else
public RabbitMqClientEventSource() : base(EventSourceSettings.EtwSelfDescribingEventFormat)
{
}
#endif

public static RabbitMqClientEventSource Log = new RabbitMqClientEventSource ();
public static RabbitMqClientEventSource Log = new RabbitMqClientEventSource();

[Event(1, Message = "INFO", Keywords = Keywords.Log, Level = EventLevel.Informational)]
public void Info(string message)
{
if(IsEnabled())
if (IsEnabled())
WriteEvent(1, message);
}

[Event(2, Message = "WARN", Keywords = Keywords.Log, Level = EventLevel.Warning)]
public void Warn(string message)
{
if(IsEnabled())
if (IsEnabled())
WriteEvent(2, message);
}
#if NET452

[Event(3, Message = "ERROR", Keywords = Keywords.Log, Level = EventLevel.Error)]
public void Error(string message, string detail)
public void Error(string message, RabbitMqExceptionDetail ex)
{
if(IsEnabled())
this.WriteEvent(3, message, detail);
}
if (IsEnabled())
{
#if NET6_0_OR_GREATER
WriteExceptionEvent(message, ex);

[UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "The properties are preserved with the DynamicallyAccessedMembers attribute.")]
void WriteExceptionEvent<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)] T>(string message, T ex)
{
WriteEvent(3, message, ex);
}
#else
[Event(3, Message = "ERROR", Keywords = Keywords.Log, Level = EventLevel.Error)]
public void Error(string message, RabbitMqExceptionDetail ex)
{
if(IsEnabled())
WriteEvent(3, message, ex);
}
#endif
}
}

[NonEvent]
public void Error(string message, Exception ex)
{

#if NET452
Error(message, ex.ToString());
#else
Error(message, new RabbitMqExceptionDetail(ex));
#endif
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public RabbitMqExceptionDetail(Exception ex)
Type = ex.GetType().FullName;
Message = ex.Message;
StackTrace = ex.StackTrace;
if(ex.InnerException != null)
if (ex.InnerException != null)
{
InnerException = ex.InnerException.ToString();
}
Expand All @@ -63,6 +63,11 @@ public RabbitMqExceptionDetail(IDictionary<string, object> ex)
}
}


// NOTE: This type is used to write EventData in RabbitMqClientEventSource.Error. To make it trim-compatible, these properties are preserved
// in RabbitMqClientEventSource. If RabbitMqExceptionDetail gets a property that is a complex type, we need to ensure the nested properties are
// preserved as well.

public string Type { get; private set; }
public string Message { get; private set; }
public string StackTrace { get; private set; }
Expand Down
2 changes: 1 addition & 1 deletion projects/Unit/APIApproval.Approve.verified.txt
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ namespace RabbitMQ.Client
System.Threading.Tasks.Task ConnectAsync(string host, int port);
System.Net.Sockets.NetworkStream GetStream();
}
public delegate void NotifyCredentialRefreshed(bool succesfully);
public delegate void NotifyCredentialRefreshed(bool successfully);
public class PlainMechanism : RabbitMQ.Client.IAuthMechanism
{
public PlainMechanism() { }
Expand Down
Loading