reflection - How to use Log4Net with interception (MS Unity) -


I am trying to use Login4Net with unity and interception ... It seems that everything works Should, but not I have two problems ... I think with a solution when I log in to the file, then I must also login to the method I am logging in. Actually, I have this configuration:

  & lt; Epander Name = "MyFile Apache" type = "log4net.Appender.RollingFileAppender" & gt; ... & lt. type = "log4net.Layout.PatternLayout" & gt; & Lt ;! -% d = date,% t = thread,% p = level,% m = message,% n = new row - & gt; & Lt; Param name = "ConversionPattern" value = "% d {dd / MMM / yyyy HH: mm} SS [% t]% -2p -% M% m% n" / & gt; & Lt; / Layout & gt; & Lt; / Appender & gt;  

I have the % M in the pattern, this method should be calling me ... but I am using interception with unity, so The login method name is INVOKE:

  var result = friendly (). Call (input, getNext);  

This is the method that calls my actual way through reflection, so how can I solve this problem by using PatternLayout of log4Net? ? Is this possible? And my second problem is, I should have two different attendants ... I will make a logger with the name MyNamespace [MyClass]. [MyMethod]

  & lt; Logger's name = "MyNamespace.MyClass.MyMethod" & gt; & Lt; Level value = "ERROR" /> & Lt; Appender-Reef Ref = "WebsiteFileAppender" /> & Lt; / Logger & gt;  

But that can not work, because I'm logging another way for log4net, which is my code instead of invoke I hope That's all that is clear.

Can anyone help me?

Thanks

Just add a custom property in your log4net thread that you log in Want to do this and want to log on to this property in the pattern.

  log4net.ThreadContext.Properties ["MyMethod"] = real-time;  

and in config

  & lt; Conversion value = "% logger (% properties {myMethod}) [% level] -% message% newline" />  

Regarding your second thing, log4net does not root the appenders based on method names, but prevents the name of the class. If you want to log some events that come only with one method, then use the property filter on the custom property you define.


Comments