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

perf in LogMessage #4453

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
23 changes: 22 additions & 1 deletion src/TestFramework/TestFramework/Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,34 @@ public static void LogMessage(string format, params object?[] args)
Guard.NotNull(format);
Guard.NotNull(args);

Delegate[] delegates = OnLogMessage.GetInvocationList();

if (delegates.Length == 0)
SimonCropp marked this conversation as resolved.
Show resolved Hide resolved
{
return;
}

string message = args.Length == 0
? format
: string.Format(CultureInfo.InvariantCulture, format, args);

if (delegates.Length == 1)
{
try
{
OnLogMessage(message);
}
catch (Exception)
{
// Catch and ignore all exceptions thrown by event handlers.
}

return;
}

object?[] parameters = [message];
// Making sure all event handlers are called in sync on same thread.
foreach (Delegate invoker in OnLogMessage.GetInvocationList())
foreach (Delegate invoker in delegates)
{
try
{
Expand Down
Loading