csnemes / tracer

Tracing rewriter using Fody
Apache License 2.0
93 stars 26 forks source link

Possible to use existing Logger instance field? #85

Open pinkfloydx33 opened 4 years ago

pinkfloydx33 commented 4 years ago

Is there a way to make use of an already existing instance field? Use case would be an ILogger<T> injected by DI, particularly in dotnet core applications. We're using Serilog under the hood, but we've already got the private instance field and would rather it delegate to that if possible. I'm not sure if this would require a new adapter based on Microsoft.Extensions.Logging.ILogger to work.

csnemes commented 4 years ago

This would be a bit complicated as the rewriter doesn't use the logger directly but through the logger adapter class (which is specific for every logger type). So the rewriter creates a static field for the LoggerAdapter and uses LoggerAdapter to create the right instance. Internally the loggerAdapter gets a real logger instance somehow and uses that to do the actual logging. So one way to reuse an existing logger would be to modify the LoggerAdapter or the LogManagerAdapter.