[ 
https://issues.apache.org/jira/browse/LOG4NET-409?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13832536#comment-13832536
 ] 

Michael Goldfinger commented on LOG4NET-409:
--------------------------------------------

The only reason I can see why generics should be used is to get rid of casting 
inside the log4net logic and gain some performance benefits out of it.
I do not believe that the performance impact would be a significant value, on 
the other hand we would gain the benefit of type safe parameters inside
the log4bet code.
To be working that way there is no need for an generic interface, just for 
generic methods like ILog.Debug<T>(T value);
This would add no complexity to the calling application since the generic is 
used implicit.
Since there is no change (or better, should be no change) in the log-logic of 
the calling application there is no need to make this decision from
an application point of view. 
This decision should only be made out of a log4net point of view for reasons 
like type-safety or simpler code.

If you need to restrict types that can be passed to the Logging object I 
suggest to use Extended Methods or a wrapper that implement the restrictions.


> Generics added to the Logger
> ----------------------------
>
>                 Key: LOG4NET-409
>                 URL: https://issues.apache.org/jira/browse/LOG4NET-409
>             Project: Log4net
>          Issue Type: Wish
>          Components: Core
>    Affects Versions: 1.3.0
>            Reporter: Ben
>              Labels: features
>
> Maybe this has been suggested before - if so sorry (I did do a search for it).
> I am fairly new to log4net and when I am using it, I was surprised to see 
> that the log methods take an object as a parameter.  Of course this made 
> sense after I found out that Object Renderers can be made to parse any type 
> of object.  I did wonder why Generics was not used.
> If I have an Object Renderer that knows how to log Orange objects then I 
> don't want to accidentally pass it an Apple object (or any other type of 
> object).
> So using Generics I would set up my logger as follows:
> private ILog<Orange> myOrangeLogger = 
> LogManager.GetLogger<Orange>("OrangeLogger");
> I have just made a special type of logger that can log oranges.  Instead of 
> accepting parameters of type object it accepts only strings and Oranges.  
> Behind the scenes the method
> LogManager.GetLogger<T>(string name) 
> would return a logger of type ILog<T>.
> The ILog<T> interface would have methods on it like:
> ILog<T>.Warn(string message);
> ILog<T>.Warn(T message);
> ILog<T>.Warn(string message, Exception ex);
> ILog<T>.Warn(T message, Exception ex);
> but would NOT have the method:
> ILog<T>.Warn(object message);
> So now if I tried to pass it an Apple object I would get a compile error 
> rather than the default behaviour for a logger which has been given an object 
> that has no special renderer (in fact I probably wouldn't even realise until 
> I went to look at the log files right?).  This would be much better and would 
> help to save me from embarrassing myself in front of my customers.
> This could be added in addition to the standard loggers which would still be 
> returned in the normal way using:
> LogManager.GetLogger(string name);
> If this has not already been suggested then I hope you like this idea.



--
This message was sent by Atlassian JIRA
(v6.1#6144)

Reply via email to