I think there may be a feature here that we can easily deliver on. Do we
think that setting arbitrary global params from the config file would be
useful?
Currently the ILoggerRepository has a Properties property which holds
key value pairs. This is designed to allow global settings to be read by
appenders etc... It is not possible to set values in this map from the
config file. It should be straight forward to add support if we decide
to do so.
The syntax in the config file would be something like:
<log4net>
<property>
<key value="foo" />
<data value="bar" />
</property>
...
</log4net>
Is this worth adding?
Will using the name 'Properties' for this get users confused with
ThreadContext.Properties?
Myself I don't see too many downsides to adding this feature, but
neither can I see many situations where it would actually help users.
Comments?
Nicko
> -----Original Message-----
> From: news [mailto:[EMAIL PROTECTED] On Behalf Of Blake Bishop
> Sent: 18 October 2005 23:41
> To: [email protected]
> Subject: Custom global param
>
> Hi all,
>
> Does the log4net framework support custom parameters that I
> can retrieve in code? Basically, I would like to set a
> property called "VERBOSITY" in the log4net config file that I
> could retrieve in code and use to manipulate my messages that
> get sent to the logger. When this value is "ON" I would
> append stack trace info to messages, regardless of the log
> level I will log the message at. I've seen a couple of
> threads about people adding log levels by rolling their own
> extensions, but I'd like to know if there is another way.
> Here is a basic example of what I'm trying to accomplish:
>
> <log4net>
> <!-- Custom parameter that can be read by my application -->
> <param name="VERBOSITY" value="ON" />
>
> <root>...</root>
> <logger>...</logger>
> ...
> </log4net>
>
> -------------------------
>
> class MyClass {
> internal static log4net.ILog log =
> log4net.LogManager.GetLogger("TestLogging");
> internal static bool isDebug = log.IsDebugEnabled;
> internal static bool isVerbose = ??????? //
>
> public void MyMethod(){
>
> // some code in some method that throws an exception
> try { //some code to try }
> catch (MyException ex) {
> string messageString = ex.Message;
> if(isVerbose) {
> // code that extracts the stack trace
> }
>
> // I could use log.Warn() or log.Info() or whatever --
> verbose-independent
> log.Error(messageString);
> }
> }
> }
>
> Thanks in advance,
> Blake
>
>
>
>
>