How to use a custom level in logger interface...

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

How to use a custom level in logger interface...

karlkras
So I've found a sample that states to add a custom level to the log4net xml configuration as such:
        <log4net>
            <level>
                <name value="AUDIT" />
                <value value="80000" />
            </level>

and I'm guessing I can define my logger to use it like this:

...
                <logger name="RollingFile" additivity="False">
                        <level value="AUDIT"/>
                </logger>

in in the C# code, how do I specify to call the logger to call the logger with the "AUDIT" level? e.g., for an Error level message I perform an log4net.ILog.Error(...) call.

what do I do for the custom level since this support isn't built in, i.e., how/where do I inject the handlers for interact with the log4net process?

thanks...
Reply | Threaded
Open this post in threaded view
|

RE: How to use a custom level in logger interface...

Brown, Michael A
Been a while since I've looked at this, but I think there is a Log() function which takes a level parameter in addition to the parameters you'd pass to Error(). Error() and related methods are just wrappers for Log() that add the appropriate level parameter. So try using Log() and passing in your custom level.
________________________________________
From: karlkras [[hidden email]]
Sent: Tuesday, April 07, 2015 19:13
To: [hidden email]
Subject: How to use a custom level in logger interface...

So I've found a sample that states to add a custom level to the log4net xml
configuration as such:
        <log4net>
            <level>
                <name value="AUDIT" />
                <value value="80000" />
            </level>

and I'm guessing I can define my logger to use it like this:

...
                <logger name="RollingFile" additivity="False">
                        <level value="AUDIT"/>
                </logger>

in in the C# code, how do I specify to call the logger to call the logger
with the "AUDIT" level? e.g., for an Error level message I perform an
log4net.ILog.Error(...) call.

what do I do for the custom level since this support isn't built in, i.e.,
how/where do I inject the handlers for interact with the log4net process?

thanks...



--
View this message in context: http://apache-logging.6191.n7.nabble.com/How-to-use-a-custom-level-in-logger-interface-tp54520.html
Sent from the Log4net - Users mailing list archive at Nabble.com.
Reply | Threaded
Open this post in threaded view
|

RE: How to use a custom level in logger interface...

karlkras
Hey Michael, not sure what you're referring to... the log.error functions are:

void Error(object message);
void Error(object message, Exception exception);

how can either of these two take a custom level?
Reply | Threaded
Open this post in threaded view
|

Re: How to use a custom level in logger interface...

Nicholas Dudas
In reply to this post by Brown, Michael A
Create a logger for each threshold level and name them appropriately.


Nick

> On Apr 8, 2015, at 3:57 AM, Brown, Michael A <[hidden email]> wrote:
>
> Been a while since I've looked at this, but I think there is a Log() function which takes a level parameter in addition to the parameters you'd pass to Error(). Error() and related methods are just wrappers for Log() that add the appropriate level parameter. So try using Log() and passing in your custom level.
> ________________________________________
> From: karlkras [[hidden email]]
> Sent: Tuesday, April 07, 2015 19:13
> To: [hidden email]
> Subject: How to use a custom level in logger interface...
>
> So I've found a sample that states to add a custom level to the log4net xml
> configuration as such:
>        <log4net>
>            <level>
>                <name value="AUDIT" />
>                <value value="80000" />
>            </level>
>
> and I'm guessing I can define my logger to use it like this:
>
> ...
>                <logger name="RollingFile" additivity="False">
>                        <level value="AUDIT"/>
>                </logger>
>
> in in the C# code, how do I specify to call the logger to call the logger
> with the "AUDIT" level? e.g., for an Error level message I perform an
> log4net.ILog.Error(...) call.
>
> what do I do for the custom level since this support isn't built in, i.e.,
> how/where do I inject the handlers for interact with the log4net process?
>
> thanks...
>
>
>
> --
> View this message in context: http://apache-logging.6191.n7.nabble.com/How-to-use-a-custom-level-in-logger-interface-tp54520.html
> Sent from the Log4net - Users mailing list archive at Nabble.com.
Reply | Threaded
Open this post in threaded view
|

RE: How to use a custom level in logger interface...

Anthony Francisco
In reply to this post by Brown, Michael A
You'll want to use:
        Log.Logger.Log(..., level, ...)

I had to dig around to find this because the documentation doesn't readily
expose that inherited methods and properties. (Been spoiled by MSDN
documentation, I suppose.) ILog derives from ILogWrapper that exposes the
Logger property. The Logger property is an ILogger that has the Log() method
that takes the level value.

- Ants

-----Original Message-----
From: Brown, Michael A [mailto:[hidden email]]
Sent: Tuesday, 07 April, 2015 22:57
To: Log4NET User
Subject: RE: How to use a custom level in logger interface...

Been a while since I've looked at this, but I think there is a Log()
function which takes a level parameter in addition to the parameters you'd
pass to Error(). Error() and related methods are just wrappers for Log()
that add the appropriate level parameter. So try using Log() and passing in
your custom level.
________________________________________
From: karlkras [[hidden email]]
Sent: Tuesday, April 07, 2015 19:13
To: [hidden email]
Subject: How to use a custom level in logger interface...

So I've found a sample that states to add a custom level to the log4net xml
configuration as such:
        <log4net>
            <level>
                <name value="AUDIT" />
                <value value="80000" />
            </level>

and I'm guessing I can define my logger to use it like this:

...
                <logger name="RollingFile" additivity="False">
                        <level value="AUDIT"/>
                </logger>

in in the C# code, how do I specify to call the logger to call the logger
with the "AUDIT" level? e.g., for an Error level message I perform an
log4net.ILog.Error(...) call.

what do I do for the custom level since this support isn't built in, i.e.,
how/where do I inject the handlers for interact with the log4net process?

thanks...



--
View this message in context:
http://apache-logging.6191.n7.nabble.com/How-to-use-a-custom-level-in-logger
-interface-tp54520.html
Sent from the Log4net - Users mailing list archive at Nabble.com.