-
Notifications
You must be signed in to change notification settings - Fork 523
Move logging to new style (remove allocs) #326
Conversation
We already have a pattern for this https://github.com/aspnet/Mvc/blob/dev/src/Microsoft.AspNet.Mvc.Core/Logging/InnerAttributeRouteLoggerExtensions.cs#L6 |
That's too weird for me :) Raised issue #327 for it instead |
Actually, quite like it, updated. Resolves #327 |
The pattern for this resolves a few perf issues by doing things like avoiding If you need to do significant work before calling the delegate, do a manual We've measured this and verified that it's allocation free when logging is off, and allocates one object when logging is on. We might take it further in the next milestone to get rid of that allocation when logging is on as well. |
_connectionWriteFin = LoggerMessage.Define<long>(LogLevel.Debug, 7, @"Connection id ""{ConnectionId}"" sending FIN."); | ||
_connectionWroteFin = LoggerMessage.Define<long, int>(LogLevel.Debug, 8, @"Connection id ""{ConnectionId}"" sent FIN with status ""{Status}""."); | ||
_connectionKeepAlive = LoggerMessage.Define<long>(LogLevel.Debug, 9, @"Connection id ""{ConnectionId}"" completed keep alive response."); | ||
_connectionDisconnect = LoggerMessage.Define<long>(LogLevel.Error, 10, @"Connection id ""{ConnectionId}"" disconnected."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should ApplicationError also use this patern?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd imagine so; but would need the following overload (as Exception
is is a built in param)?
static Action<ILogger, Exception> Define(LogLevel logLevel, int eventId, string formatString)
in Microsoft.Extensions.Logging.Abstractions/LoggerMessage.cs
which doesn't currently exist.
6d792bb
to
98dcd71
Compare
e482ddf
to
69e15c7
Compare
d1954f4
to
c0f8276
Compare
and additionally boxing param issue shown below:
Takes allocations for logging calls to zero