-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Developers using ILogger have improved performance #48619
Comments
TODO: Add Fortunes/EF/MVC/HTTPS scenario with loggers turned on (nothing logged) and re-enable Json Middleware with logging. |
Tagging subscribers to this area: @maryamariyan Issue DetailsImprove performance characteristics of Logging. Areas of interest:
|
Here's an isolated benchmark for no-op vs disabled use case: (I had to loop 1000 times for a proper diff to show up between the two cases) For benchmarks [Benchmark]
public void LogDebug()
{
for (int i = 0; i < 1000; i++)
_logger.LogDebug(@"Connection id '{connectionId}', range [{start}..{end}], options {options}", ConnectionId, Start, End, Options);
}
[Benchmark]
public void LoggerMessage()
{
for (int i = 0; i < 1000; i++)
_loggerMessage2(_logger, ConnectionId, Start, End, Options, null);
} where private static Action<ILogger, string, long, long, int, Exception?> _loggerMessage2 = LoggerMessage.Define<string, long, long, int>(LogLevel.Debug,
eventId: 381,
formatString: @"Connection id '{connectionId}', range [{start}..{end}], options {options}"); and Using // noop (logger.IsEnabled(LogLevel.Debug) will be false here)
.AddLogging(logBuilder =>
{
logBuilder.AddConsole().SetMinimumLevel(LogLevel.Information);
}) We get
and using // disabled
.AddLogging(logBuilder =>
{
logBuilder.ClearProviders();
}) we get:
link to gist Here's another perf report using Microsoft.Crank: https://gist.github.com/maryamariyan/06370e90cdc7809037de59a88662d9d6
These benchmarks show there is definitely a perf overhead with adding logging providers |
I added more benchmarks and a little report with a set of logging use cases here: https://gist.github.com/maryamariyan/0bad4136655f344bf203274e5b7431b4 |
Improve performance characteristics of Logging.
Areas of interest:
Issues:
The text was updated successfully, but these errors were encountered: