0
votes

In the past I have use the Log4Net ILog interface and custom database appenders to log objects to a database. This is very useful for capturing contextual information such as the machine name, current user, HTTP request details, etc, when logging certain kinds of events.

I am now looking at doing the same sort of thing but using IoC via Castle.Windsor. The problem is that Castle's ILogger abstraction does not support the logging of objects. Since I don't really need the abstraction nor support for other logging frameworks, is there another Log4Net integration facility out there that will support injecting ILog instances, or can I get ILog instances from the Windsor logging facility?

1
I don't understand the question. I don't use Castle.Windsor, but by looking at their source here: github.com/castleproject/Castle.Core I can see that their ILogger signatures (DebugFormat, InfoFormat, etc) take objects as parameters. Also, if you use their ExtendedLog4netLogger, you can use GlobalProperties or ThreadProperties to store objects in the corresponding log4net properties objects. Can you give some examples of stuff that works in log4net that you cannot do with Castle?wageoghe
@wageoghe: What I am looking for is a means to pass an object that will be assigned to the MessageObject property of the LoggingEvent type which is ultimately passed by Log4Net to my customer appender's Append method. To my knowledge, the objects accepted on the XXXFormat methods are only used in conjunction with the format string provided in order to call string.Format(...). In the LoggingEvent passed to the appender, the resulting string is assigned to the RenderedMessage property but the original object references are passed.Kenneth Baltrinic
Ok, I get it. So you are using the Log method from log4net's ILogger interface. I'm not aware of any off the shelf log4net abstractions that expose the Log method. I am using Common.Logging and in one usage I need the Log method. In my case, it is in the implementation of a logging WCF service. I just wrote my own log4net Factory adapter (see Common.Logging for what this is) and had it return my own loggers. My loggers implement a Log function that delegate to the log4net Log function.wageoghe
This works well enough for our needs, but I don't know if it will really help you. Otherwise, I suppose that you could write your own abstraction and inject it with Castle.Windsor, but it sounds like you are not looking for this kind of solution at this point.wageoghe
CORRECTION to my last comment. The last sentence should read "...the original object references are NOT passed."Kenneth Baltrinic

1 Answers

0
votes

Ultimately, I solved this by implementing my own facility based on the Castle logging facility source code but returning the log4Net specific interface.