Hi! i'm wondering if there is any way to change class name of logger instance at runtime ? i want not to create logger in every class but to inject it via constructor. but after i do it i get in file wrong class name which invokes the event
It doesn't really look like you are calling c1.LogSomething in that example. But that's the behaviour I'd expect. My understanding is that if you want separate logging names then you need to create separate instances of logger using
LogManager.GetCurrentClassLogger() which will give you logging instances named c1 and c2 as you seem to want.
LogManager.GetLogger("c1") and LogManager.GetLogger("c2") which would give you the same result.
Why do you want to share the logger between the two classes? You can still configure two Loggers to the same target if that's what you want.
Again, I'm newish to NLog so I'm happy to be corrected and interested to know if there are any problems with the approach of using multiple instances rather than sharing them. Given that LogManager is essentially a Factory I'd expect them all to be connected to the same LogManager, but how many is too many?? I'm not sure of that.
Thanks for your reply, Mark! it will be very hard to test your app if you'll create each logger instance in its own class, better inject it via contructor. In this case you'll be able to mock your logger instance.
and about question how many is too many: it cares me too...