exceptionless / Exceptionless.Net

Exceptionless clients for the .NET platform
https://exceptionless.com
Other
554 stars 142 forks source link

Log4Net Appender - Add custom properties (for example timeElapsed) #223

Closed janniksam closed 4 years ago

janniksam commented 4 years ago

We are currently implementing Log4Net in a way, that a lot of our methods implementations are wrapped in a using block similar to this one:

using (m_log.CreateScope(nameof(MyMethod))
{
     //methods impl
}

Inside the CreateScope we have something like this, which is written to the our log file (and in the future it could be sent to eventless aswell):

m_logger.DebugFormat("{0} (Execution took {1} ms)", sb.ToString(), elapsed);

I would like to know if there is a possibility in the Log4Net appender implementation, that allows me to add custom properties like TimeElapsed, which I can use to filter in the dashboard later on. I saw Serilog and NLog having an implementation for that (atleast I think so), so I was wondering, if there is one for the "oldschool" Log4Net aswell.

niemyjski commented 4 years ago

Yes, this should be handled already as shown here: https://github.com/exceptionless/Exceptionless.Net/blob/master/src/Platforms/Exceptionless.Log4net/ExceptionlessClientExtensions.cs#L23-L29

I'd recommend using structured logging and naming your interpolation expression (I think that's the term for naming {0) -> {Elapsed:g}), otherwise we might not include it. If it's not can you comment and let us know and we'll reopen this.