You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4net-dev@logging.apache.org by "Farrington, Linda" <lf...@aclara.com> on 2013/07/30 17:31:37 UTC

asynchronous logging

We are trying to log asynchronously using an asynchronousadonetappender inherited from adonetappender.   Logging standard properties seems to work fine, but custom properties do not.  I understand that this is because the asynchronous appender is logging the messages on another thread and we're storing the custom properties in the logicalthreadcontext (tried threadcontext = as well to no avail).  My question is this:  If I cannot use the threadcontext when running asynchronously, how should I pass custom properties into log4net.  Has anyone else done this?  Can anyone provide any suggestions?



Thanks in advance,



Linda





Re: asynchronous logging

Posted by Michael Schall <mi...@gmail.com>.
You could try the BufferingForwardingAppender.  We use this while writing
to a file (we usually buffer up 512 events) and I believe we use
LogicalThreadContext for certain things we want logged.  You can setup an
evaluator so that the buffer is flushed at certain times other than size.
 We do so if the threshold is WARN or higher so it will be flushed on error
before the process dies.  I think the way it works is the message is
created when logged, but then added to a memory queue and sent to whatever
appenders you want when flushed.  Also, make sure you set lossy to false or
else messages will be thrown away rather than flushing the buffer when it
reaches the bufferSize.

    <appender name="BufferingForwardingAppender"
type="log4net.Appender.BufferingForwardingAppender" >
        <bufferSize value="512" />
        <lossy value="false" />
        <evaluator type="log4net.Core.LevelEvaluator">
            <threshold value="WARN"/>
        </evaluator>
        <appender-ref ref="RollingFile" />
    </appender>

Hope this helps

Mike


On Tue, Jul 30, 2013 at 10:31 AM, Farrington, Linda
<lf...@aclara.com>wrote:

>  We are trying to log asynchronously using an asynchronousadonetappender
> inherited from adonetappender.   Logging standard properties seems to work
> fine, but custom properties do not.  I understand that this is because the
> asynchronous appender is logging the messages on another thread and we're
> storing the custom properties in the logicalthreadcontext (tried
> threadcontext = as well to no avail).  My question is this:  If I cannot
> use the threadcontext when running asynchronously, how should I pass custom
> properties into log4net.  Has anyone else done this?  Can anyone provide
> any suggestions?****
>
> ** **
>
> Thanks in advance,****
>
> ** **
>
> Linda****
>
> ** **
>
> ** **
>
> ** **
>

Re: asynchronous logging

Posted by George Chung <ge...@glympse.com>.
Couldn't you just stuff away a static reference to the Main thread? And get
its ThreadingContext from that reference?


On Tue, Jul 30, 2013 at 2:42 PM, Farrington, Linda
<lf...@aclara.com>wrote:

>  Chinh Do,****
>
> Thanks for your suggestion.  This sounds like it might work.  I did not
> write this component, we are using one that someone else wrote and posted
> on github.  Are you talking about the Properties() that is on the
> LoggingEvent object?  If so, there is a point in the code where I see the
> correct data in ThreadingContext.  I could get it out of there and put it
> into Properties.  However, I have not been able to find a way to iterate
> through the ThreadingContext because it does not have a GetEnumerator on
> it. How are you able to get data out of the threadContext?****
>
> ** **
>
> *From:* chinhdo@gmail.com [mailto:chinhdo@gmail.com] *On Behalf Of *Chinh
> Do
> *Sent:* Tuesday, July 30, 2013 4:28 PM
> *To:* Log4NET Dev
> *Subject:* Re: asynchronous logging****
>
> ** **
>
> What I did my my AsyncAppender was to write thread specific data into
> loggingEvent.Properties in the main thread, just before I add the
> loggingEvent to a queue. Then you can use "%P{<PropertyName>}" in your
> log4net config section to get them later in the other thread.****
>
> ** **
>
> My AsyncAppender was based on log4net AsyncAppender example (see
> http://logging.apache.org/log4net/release/example-apps.html). The log
> events sent to AsyncAppender are forwarded asynchronously to a list of
> attached appenders.****
>
> ** **
>
> On Tue, Jul 30, 2013 at 2:31 PM, George Chung <ge...@glympse.com> wrote:*
> ***
>
> If you authored your own AsynchronousAdoNetAppender that uses the new .NET
> async/await constructs, you could use the TPL library to wrap the ado.netasync operations as a Task.
> ****
>
> ** **
>
> Then if you *avoid *calling ConfigureAwait(false), I'm pretty sure the
> completion routine will complete on the original ASP.NET request thread,
> in which case you'll have access to the original HttpContext that started
> the request.****
>
> ** **
>
> ** **
>
> On Tue, Jul 30, 2013 at 8:31 AM, Farrington, Linda <lf...@aclara.com>
> wrote:****
>
> We are trying to log asynchronously using an asynchronousadonetappender
> inherited from adonetappender.   Logging standard properties seems to work
> fine, but custom properties do not.  I understand that this is because the
> asynchronous appender is logging the messages on another thread and we're
> storing the custom properties in the logicalthreadcontext (tried
> threadcontext = as well to no avail).  My question is this:  If I cannot
> use the threadcontext when running asynchronously, how should I pass custom
> properties into log4net.  Has anyone else done this?  Can anyone provide
> any suggestions?****
>
>  ****
>
> Thanks in advance,****
>
>  ****
>
> Linda****
>
>  ****
>
>  ****
>
>  ****
>
> ** **
>
>
>
> ****
>
> ** **
>
> --
> http://www.chinhdo.com ****
>

Re: asynchronous logging

Posted by Dominik Psenner <dp...@gmail.com>.
Feel free to reuse whatever you need from the log4net source as long as you
respect the ASF license.


2013/7/31 Farrington, Linda <lf...@aclara.com>

>  Dominik,****
>
> ** **
>
> I know.  I can’t either.  The only thing I could think of it that it is
> some security hole.  Will open up an issue.  (Do you know if there is a
> method I could use to read the configuration dynamically?  I can just write
> the code to do it from scratch, but if something already exists then I’d
> rather leverage that.****
>
> ** **
>
> Thanks,****
>
> ** **
>
> Linda****
>
> ** **
>
> *From:* Dominik Psenner [mailto:dpsenner@gmail.com]
> *Sent:* Wednesday, July 31, 2013 2:42 PM
>
> *To:* Log4NET Dev
> *Subject:* Re: asynchronous logging****
>
> ** **
>
> I see your point. In ThreadContext there's no way to get to the keys, even
> though internally a dictionary is used. Please open a JIRA issue on this.
> Can't think about a reason why there shouldn't be a keys getter.****
>
> ** **
>
> 2013/7/31 Farrington, Linda <lf...@aclara.com>****
>
> Dominik,****
>
>  ****
>
> I don’t think you’ve seen the object that I’m talking about.  There is no
> getkeys() method on the threadcontext.  That’s why I have the issue in the
> first place.  Looks like I’ll need to read the configuration file to get
> the property names.  There is a getProperties method on the object, but it
> is declared as internal and so I cannot access it.****
>
>  ****
>
> Thanks for trying though****
>
>  ****
>
> *From:* Dominik Psenner [mailto:dpsenner@gmail.com]
> *Sent:* Wednesday, July 31, 2013 2:00 PM****
>
>
> *To:* Log4NET Dev
> *Subject:* Re: asynchronous logging****
>
>  ****
>
> Easy as that:****
>
>  ****
>
>
> http://logging.apache.org/log4net/release/sdk/log4net.Util.ReadOnlyPropertiesDictionary.GetKeys.html
> ****
>
>  ****
>
> 2013/7/31 Farrington, Linda <lf...@aclara.com>****
>
> Dominik,****
>
>  ****
>
> Seems obvious, but in our case, it’s not.   I am working within some apps
> that already exist that are calling this logging and trying to make these
> changes without disrupting them.    ****
>
>  ****
>
> The app calls the logging like so:****
>
> Push properties onto the threadcontext  (fill threadcontext.properties)***
> *
>
> Call Log.Debug  to log the error.  At this point, I am now in the append
> method in the asynchronous appender.  I have only the threading context to
> work with.  I don’t see an overload to pass additional properites.  So I am
> not sure how creating a separate properties dictionary would solve this.
> (I am new to log4net, so it’s possible I am missing the obvious)****
>
>  ****
>
> Thanks,****
>
>  ****
>
> Linda****
>
>  ****
>
> *From:* Dominik Psenner [mailto:dpsenner@gmail.com]
> *Sent:* Wednesday, July 31, 2013 9:25 AM****
>
>
> *To:* Log4NET Dev
> *Subject:* Re: asynchronous logging****
>
>  ****
>
> I may be pointing out the obvious, but why don't you let both applications
> write to the same key a collection which lets your third application
> determine which fields are being sent:
>
> string[] fields = Properties["fields"];
> foreach(string field in fields) {
>     string value = Properties[field];
> }
>
> Cheers
>
> On 07/31/2013 03:10 PM, Farrington, Linda wrote:****
>
> My data is coming to me in the ThreadingContext.Properties collection.
> There are about 10 elements in there.  I can’t seem to find a way to get
> the data out of this collection as there is no way to iterate it and I
> don’t know what the fields are named.  (We have two different applications
> and they pass in different data in the collection.****
>
>  ****
>
> *From:* chinhdo@gmail.com [mailto:chinhdo@gmail.com <ch...@gmail.com>] *On
> Behalf Of *Chinh Do
> *Sent:* Tuesday, July 30, 2013 10:07 PM
> *To:* Log4NET Dev
> *Subject:* Re: asynchronous logging****
>
>  ****
>
> Yes I was referring to log4net.Core.LoggingEvent.Properties.****
>
>  ****
>
> In my case, I know exactly what I need so I just had a few lines of code
> like this:****
>
>  ****
>
> // Implementation of IAppender.DoAppend****
>
> public void DoAppend(LoggingEvent loggingEvent) {****
>
>     loggingEvent.Properties["ThreadId"] =
> Thread.CurrentThread.ManagedThreadId.ToString();****
>
>     loggingEvent.Properties["MyUserId"] = ...****
>
>     loggingEvent.Properties["MySessionId"] = ...****
>
>     ...****
>
>     AddToQueue(loggingEvent);****
>
> }****
>
>  ****
>
>  ****
>
> On Tue, Jul 30, 2013 at 5:42 PM, Farrington, Linda <lf...@aclara.com>
> wrote:****
>
> Chinh Do,****
>
> Thanks for your suggestion.  This sounds like it might work.  I did not
> write this component, we are using one that someone else wrote and posted
> on github.  Are you talking about the Properties() that is on the
> LoggingEvent object?  If so, there is a point in the code where I see the
> correct data in ThreadingContext.  I could get it out of there and put it
> into Properties.  However, I have not been able to find a way to iterate
> through the ThreadingContext because it does not have a GetEnumerator on
> it. How are you able to get data out of the threadContext?****
>
>  ****
>
> *From:* chinhdo@gmail.com [mailto:chinhdo@gmail.com] *On Behalf Of *Chinh
> Do
> *Sent:* Tuesday, July 30, 2013 4:28 PM
> *To:* Log4NET Dev
> *Subject:* Re: asynchronous logging****
>
>  ****
>
> What I did my my AsyncAppender was to write thread specific data into
> loggingEvent.Properties in the main thread, just before I add the
> loggingEvent to a queue. Then you can use "%P{<PropertyName>}" in your
> log4net config section to get them later in the other thread.****
>
>  ****
>
> My AsyncAppender was based on log4net AsyncAppender example (see
> http://logging.apache.org/log4net/release/example-apps.html). The log
> events sent to AsyncAppender are forwarded asynchronously to a list of
> attached appenders.****
>
>  ****
>
> On Tue, Jul 30, 2013 at 2:31 PM, George Chung <ge...@glympse.com> wrote:*
> ***
>
> If you authored your own AsynchronousAdoNetAppender that uses the new .NET
> async/await constructs, you could use the TPL library to wrap the ado.netasync operations as a Task.
> ****
>
>  ****
>
> Then if you *avoid *calling ConfigureAwait(false), I'm pretty sure the
> completion routine will complete on the original ASP.NET request thread,
> in which case you'll have access to the original HttpContext that started
> the request.****
>
>  ****
>
>  ****
>
> On Tue, Jul 30, 2013 at 8:31 AM, Farrington, Linda <lf...@aclara.com>
> wrote:****
>
> We are trying to log asynchronously using an asynchronousadonetappender
> inherited from adonetappender.   Logging standard properties seems to work
> fine, but custom properties do not.  I understand that this is because the
> asynchronous appender is logging the messages on another thread and we're
> storing the custom properties in the logicalthreadcontext (tried
> threadcontext = as well to no avail).  My question is this:  If I cannot
> use the threadcontext when running asynchronously, how should I pass custom
> properties into log4net.  Has anyone else done this?  Can anyone provide
> any suggestions?****
>
>  ****
>
> Thanks in advance,****
>
>  ****
>
> Linda****
>
>  ****
>
>  ****
>
>  ****
>
>  ****
>
>
>
> ****
>
>  ****
>
> --
> http://www.chinhdo.com ** **
>
>
>
> ****
>
>  ****
>
> --
> http://www.chinhdo.com ** **
>
>  ****
>
>
>
> ****
>
>  ****
>
> --
> Dominik Psenner
> ## OpenPGP Key Signature #################################
> # Key ID: B469318C                                       #
> # Fingerprint: 558641995F7EC2D251354C3A49C7E3D1B469318C  #
> ##########################################################****
>
>
>
> ****
>
> ** **
>
> --
> Dominik Psenner
> ## OpenPGP Key Signature #################################
> # Key ID: B469318C                                       #
> # Fingerprint: 558641995F7EC2D251354C3A49C7E3D1B469318C  #
> ##########################################################****
>



-- 
Dominik Psenner
## OpenPGP Key Signature #################################
# Key ID: B469318C                                       #
# Fingerprint: 558641995F7EC2D251354C3A49C7E3D1B469318C  #
##########################################################

RE: asynchronous logging

Posted by "Farrington, Linda" <lf...@aclara.com>.
Dominik,

I know.  I can't either.  The only thing I could think of it that it is some security hole.  Will open up an issue.  (Do you know if there is a method I could use to read the configuration dynamically?  I can just write the code to do it from scratch, but if something already exists then I'd rather leverage that.

Thanks,

Linda

From: Dominik Psenner [mailto:dpsenner@gmail.com]
Sent: Wednesday, July 31, 2013 2:42 PM
To: Log4NET Dev
Subject: Re: asynchronous logging

I see your point. In ThreadContext there's no way to get to the keys, even though internally a dictionary is used. Please open a JIRA issue on this. Can't think about a reason why there shouldn't be a keys getter.

2013/7/31 Farrington, Linda <lf...@aclara.com>>
Dominik,

I don't think you've seen the object that I'm talking about.  There is no getkeys() method on the threadcontext.  That's why I have the issue in the first place.  Looks like I'll need to read the configuration file to get the property names.  There is a getProperties method on the object, but it is declared as internal and so I cannot access it.

Thanks for trying though

From: Dominik Psenner [mailto:dpsenner@gmail.com<ma...@gmail.com>]
Sent: Wednesday, July 31, 2013 2:00 PM

To: Log4NET Dev
Subject: Re: asynchronous logging

Easy as that:

http://logging.apache.org/log4net/release/sdk/log4net.Util.ReadOnlyPropertiesDictionary.GetKeys.html

2013/7/31 Farrington, Linda <lf...@aclara.com>>
Dominik,

Seems obvious, but in our case, it's not.   I am working within some apps that already exist that are calling this logging and trying to make these changes without disrupting them.

The app calls the logging like so:
Push properties onto the threadcontext  (fill threadcontext.properties)
Call Log.Debug  to log the error.  At this point, I am now in the append method in the asynchronous appender.  I have only the threading context to work with.  I don't see an overload to pass additional properites.  So I am not sure how creating a separate properties dictionary would solve this.  (I am new to log4net, so it's possible I am missing the obvious)

Thanks,

Linda

From: Dominik Psenner [mailto:dpsenner@gmail.com<ma...@gmail.com>]
Sent: Wednesday, July 31, 2013 9:25 AM

To: Log4NET Dev
Subject: Re: asynchronous logging

I may be pointing out the obvious, but why don't you let both applications write to the same key a collection which lets your third application determine which fields are being sent:

string[] fields = Properties["fields"];
foreach(string field in fields) {
    string value = Properties[field];
}

Cheers

On 07/31/2013 03:10 PM, Farrington, Linda wrote:
My data is coming to me in the ThreadingContext.Properties collection.  There are about 10 elements in there.  I can't seem to find a way to get the data out of this collection as there is no way to iterate it and I don't know what the fields are named.  (We have two different applications and they pass in different data in the collection.

From: chinhdo@gmail.com<ma...@gmail.com> [mailto:chinhdo@gmail.com] On Behalf Of Chinh Do
Sent: Tuesday, July 30, 2013 10:07 PM
To: Log4NET Dev
Subject: Re: asynchronous logging

Yes I was referring to log4net.Core.LoggingEvent.Properties.

In my case, I know exactly what I need so I just had a few lines of code like this:

// Implementation of IAppender.DoAppend
public void DoAppend(LoggingEvent loggingEvent) {
    loggingEvent.Properties["ThreadId"] = Thread.CurrentThread.ManagedThreadId.ToString();
    loggingEvent.Properties["MyUserId"] = ...
    loggingEvent.Properties["MySessionId"] = ...
    ...
    AddToQueue(loggingEvent);
}


On Tue, Jul 30, 2013 at 5:42 PM, Farrington, Linda <lf...@aclara.com>> wrote:
Chinh Do,
Thanks for your suggestion.  This sounds like it might work.  I did not write this component, we are using one that someone else wrote and posted on github.  Are you talking about the Properties() that is on the LoggingEvent object?  If so, there is a point in the code where I see the correct data in ThreadingContext.  I could get it out of there and put it into Properties.  However, I have not been able to find a way to iterate through the ThreadingContext because it does not have a GetEnumerator on it. How are you able to get data out of the threadContext?

From: chinhdo@gmail.com<ma...@gmail.com> [mailto:chinhdo@gmail.com<ma...@gmail.com>] On Behalf Of Chinh Do
Sent: Tuesday, July 30, 2013 4:28 PM
To: Log4NET Dev
Subject: Re: asynchronous logging

What I did my my AsyncAppender was to write thread specific data into loggingEvent.Properties in the main thread, just before I add the loggingEvent to a queue. Then you can use "%P{<PropertyName>}" in your log4net config section to get them later in the other thread.

My AsyncAppender was based on log4net AsyncAppender example (see http://logging.apache.org/log4net/release/example-apps.html). The log events sent to AsyncAppender are forwarded asynchronously to a list of attached appenders.

On Tue, Jul 30, 2013 at 2:31 PM, George Chung <ge...@glympse.com>> wrote:
If you authored your own AsynchronousAdoNetAppender that uses the new .NET async/await constructs, you could use the TPL library to wrap the ado.net<http://ado.net> async operations as a Task.

Then if you avoid calling ConfigureAwait(false), I'm pretty sure the completion routine will complete on the original ASP.NET<http://ASP.NET> request thread, in which case you'll have access to the original HttpContext that started the request.


On Tue, Jul 30, 2013 at 8:31 AM, Farrington, Linda <lf...@aclara.com>> wrote:

We are trying to log asynchronously using an asynchronousadonetappender inherited from adonetappender.   Logging standard properties seems to work fine, but custom properties do not.  I understand that this is because the asynchronous appender is logging the messages on another thread and we're storing the custom properties in the logicalthreadcontext (tried threadcontext = as well to no avail).  My question is this:  If I cannot use the threadcontext when running asynchronously, how should I pass custom properties into log4net.  Has anyone else done this?  Can anyone provide any suggestions?



Thanks in advance,



Linda








--
http://www.chinhdo.com



--
http://www.chinhdo.com




--
Dominik Psenner
## OpenPGP Key Signature #################################
# Key ID: B469318C                                       #
# Fingerprint: 558641995F7EC2D251354C3A49C7E3D1B469318C  #
##########################################################



--
Dominik Psenner
## OpenPGP Key Signature #################################
# Key ID: B469318C                                       #
# Fingerprint: 558641995F7EC2D251354C3A49C7E3D1B469318C  #
##########################################################

Re: asynchronous logging

Posted by Dominik Psenner <dp...@gmail.com>.
I see your point. In ThreadContext there's no way to get to the keys, even
though internally a dictionary is used. Please open a JIRA issue on this.
Can't think about a reason why there shouldn't be a keys getter.


2013/7/31 Farrington, Linda <lf...@aclara.com>

>  Dominik,****
>
> ** **
>
> I don’t think you’ve seen the object that I’m talking about.  There is no
> getkeys() method on the threadcontext.  That’s why I have the issue in the
> first place.  Looks like I’ll need to read the configuration file to get
> the property names.  There is a getProperties method on the object, but it
> is declared as internal and so I cannot access it.****
>
> ** **
>
> Thanks for trying though****
>
> ** **
>
> *From:* Dominik Psenner [mailto:dpsenner@gmail.com]
> *Sent:* Wednesday, July 31, 2013 2:00 PM
>
> *To:* Log4NET Dev
> *Subject:* Re: asynchronous logging****
>
> ** **
>
> Easy as that:****
>
> ** **
>
>
> http://logging.apache.org/log4net/release/sdk/log4net.Util.ReadOnlyPropertiesDictionary.GetKeys.html
> ****
>
> ** **
>
> 2013/7/31 Farrington, Linda <lf...@aclara.com>****
>
> Dominik,****
>
>  ****
>
> Seems obvious, but in our case, it’s not.   I am working within some apps
> that already exist that are calling this logging and trying to make these
> changes without disrupting them.    ****
>
>  ****
>
> The app calls the logging like so:****
>
> Push properties onto the threadcontext  (fill threadcontext.properties)***
> *
>
> Call Log.Debug  to log the error.  At this point, I am now in the append
> method in the asynchronous appender.  I have only the threading context to
> work with.  I don’t see an overload to pass additional properites.  So I am
> not sure how creating a separate properties dictionary would solve this.
> (I am new to log4net, so it’s possible I am missing the obvious)****
>
>  ****
>
> Thanks,****
>
>  ****
>
> Linda****
>
>  ****
>
> *From:* Dominik Psenner [mailto:dpsenner@gmail.com]
> *Sent:* Wednesday, July 31, 2013 9:25 AM****
>
>
> *To:* Log4NET Dev
> *Subject:* Re: asynchronous logging****
>
>  ****
>
> I may be pointing out the obvious, but why don't you let both applications
> write to the same key a collection which lets your third application
> determine which fields are being sent:
>
> string[] fields = Properties["fields"];
> foreach(string field in fields) {
>     string value = Properties[field];
> }
>
> Cheers
>
> On 07/31/2013 03:10 PM, Farrington, Linda wrote:****
>
> My data is coming to me in the ThreadingContext.Properties collection.
> There are about 10 elements in there.  I can’t seem to find a way to get
> the data out of this collection as there is no way to iterate it and I
> don’t know what the fields are named.  (We have two different applications
> and they pass in different data in the collection.****
>
>  ****
>
> *From:* chinhdo@gmail.com [mailto:chinhdo@gmail.com <ch...@gmail.com>] *On
> Behalf Of *Chinh Do
> *Sent:* Tuesday, July 30, 2013 10:07 PM
> *To:* Log4NET Dev
> *Subject:* Re: asynchronous logging****
>
>  ****
>
> Yes I was referring to log4net.Core.LoggingEvent.Properties.****
>
>  ****
>
> In my case, I know exactly what I need so I just had a few lines of code
> like this:****
>
>  ****
>
> // Implementation of IAppender.DoAppend****
>
> public void DoAppend(LoggingEvent loggingEvent) {****
>
>     loggingEvent.Properties["ThreadId"] =
> Thread.CurrentThread.ManagedThreadId.ToString();****
>
>     loggingEvent.Properties["MyUserId"] = ...****
>
>     loggingEvent.Properties["MySessionId"] = ...****
>
>     ...****
>
>     AddToQueue(loggingEvent);****
>
> }****
>
>  ****
>
>  ****
>
> On Tue, Jul 30, 2013 at 5:42 PM, Farrington, Linda <lf...@aclara.com>
> wrote:****
>
> Chinh Do,****
>
> Thanks for your suggestion.  This sounds like it might work.  I did not
> write this component, we are using one that someone else wrote and posted
> on github.  Are you talking about the Properties() that is on the
> LoggingEvent object?  If so, there is a point in the code where I see the
> correct data in ThreadingContext.  I could get it out of there and put it
> into Properties.  However, I have not been able to find a way to iterate
> through the ThreadingContext because it does not have a GetEnumerator on
> it. How are you able to get data out of the threadContext?****
>
>  ****
>
> *From:* chinhdo@gmail.com [mailto:chinhdo@gmail.com] *On Behalf Of *Chinh
> Do
> *Sent:* Tuesday, July 30, 2013 4:28 PM
> *To:* Log4NET Dev
> *Subject:* Re: asynchronous logging****
>
>  ****
>
> What I did my my AsyncAppender was to write thread specific data into
> loggingEvent.Properties in the main thread, just before I add the
> loggingEvent to a queue. Then you can use "%P{<PropertyName>}" in your
> log4net config section to get them later in the other thread.****
>
>  ****
>
> My AsyncAppender was based on log4net AsyncAppender example (see
> http://logging.apache.org/log4net/release/example-apps.html). The log
> events sent to AsyncAppender are forwarded asynchronously to a list of
> attached appenders.****
>
>  ****
>
> On Tue, Jul 30, 2013 at 2:31 PM, George Chung <ge...@glympse.com> wrote:*
> ***
>
> If you authored your own AsynchronousAdoNetAppender that uses the new .NET
> async/await constructs, you could use the TPL library to wrap the ado.netasync operations as a Task.
> ****
>
>  ****
>
> Then if you *avoid *calling ConfigureAwait(false), I'm pretty sure the
> completion routine will complete on the original ASP.NET request thread,
> in which case you'll have access to the original HttpContext that started
> the request.****
>
>  ****
>
>  ****
>
> On Tue, Jul 30, 2013 at 8:31 AM, Farrington, Linda <lf...@aclara.com>
> wrote:****
>
> We are trying to log asynchronously using an asynchronousadonetappender
> inherited from adonetappender.   Logging standard properties seems to work
> fine, but custom properties do not.  I understand that this is because the
> asynchronous appender is logging the messages on another thread and we're
> storing the custom properties in the logicalthreadcontext (tried
> threadcontext = as well to no avail).  My question is this:  If I cannot
> use the threadcontext when running asynchronously, how should I pass custom
> properties into log4net.  Has anyone else done this?  Can anyone provide
> any suggestions?****
>
>  ****
>
> Thanks in advance,****
>
>  ****
>
> Linda****
>
>  ****
>
>  ****
>
>  ****
>
>  ****
>
>
>
> ****
>
>  ****
>
> --
> http://www.chinhdo.com ** **
>
>
>
> ****
>
>  ****
>
> --
> http://www.chinhdo.com ** **
>
>  ****
>
>
>
> ****
>
> ** **
>
> --
> Dominik Psenner
> ## OpenPGP Key Signature #################################
> # Key ID: B469318C                                       #
> # Fingerprint: 558641995F7EC2D251354C3A49C7E3D1B469318C  #
> ##########################################################****
>



-- 
Dominik Psenner
## OpenPGP Key Signature #################################
# Key ID: B469318C                                       #
# Fingerprint: 558641995F7EC2D251354C3A49C7E3D1B469318C  #
##########################################################

RE: asynchronous logging

Posted by "Farrington, Linda" <lf...@aclara.com>.
Dominik,

I don't think you've seen the object that I'm talking about.  There is no getkeys() method on the threadcontext.  That's why I have the issue in the first place.  Looks like I'll need to read the configuration file to get the property names.  There is a getProperties method on the object, but it is declared as internal and so I cannot access it.

Thanks for trying though

From: Dominik Psenner [mailto:dpsenner@gmail.com]
Sent: Wednesday, July 31, 2013 2:00 PM
To: Log4NET Dev
Subject: Re: asynchronous logging

Easy as that:

http://logging.apache.org/log4net/release/sdk/log4net.Util.ReadOnlyPropertiesDictionary.GetKeys.html

2013/7/31 Farrington, Linda <lf...@aclara.com>>
Dominik,

Seems obvious, but in our case, it's not.   I am working within some apps that already exist that are calling this logging and trying to make these changes without disrupting them.

The app calls the logging like so:
Push properties onto the threadcontext  (fill threadcontext.properties)
Call Log.Debug  to log the error.  At this point, I am now in the append method in the asynchronous appender.  I have only the threading context to work with.  I don't see an overload to pass additional properites.  So I am not sure how creating a separate properties dictionary would solve this.  (I am new to log4net, so it's possible I am missing the obvious)

Thanks,

Linda

From: Dominik Psenner [mailto:dpsenner@gmail.com<ma...@gmail.com>]
Sent: Wednesday, July 31, 2013 9:25 AM

To: Log4NET Dev
Subject: Re: asynchronous logging

I may be pointing out the obvious, but why don't you let both applications write to the same key a collection which lets your third application determine which fields are being sent:

string[] fields = Properties["fields"];
foreach(string field in fields) {
    string value = Properties[field];
}

Cheers

On 07/31/2013 03:10 PM, Farrington, Linda wrote:
My data is coming to me in the ThreadingContext.Properties collection.  There are about 10 elements in there.  I can't seem to find a way to get the data out of this collection as there is no way to iterate it and I don't know what the fields are named.  (We have two different applications and they pass in different data in the collection.

From: chinhdo@gmail.com<ma...@gmail.com> [mailto:chinhdo@gmail.com] On Behalf Of Chinh Do
Sent: Tuesday, July 30, 2013 10:07 PM
To: Log4NET Dev
Subject: Re: asynchronous logging

Yes I was referring to log4net.Core.LoggingEvent.Properties.

In my case, I know exactly what I need so I just had a few lines of code like this:

// Implementation of IAppender.DoAppend
public void DoAppend(LoggingEvent loggingEvent) {
    loggingEvent.Properties["ThreadId"] = Thread.CurrentThread.ManagedThreadId.ToString();
    loggingEvent.Properties["MyUserId"] = ...
    loggingEvent.Properties["MySessionId"] = ...
    ...
    AddToQueue(loggingEvent);
}


On Tue, Jul 30, 2013 at 5:42 PM, Farrington, Linda <lf...@aclara.com>> wrote:
Chinh Do,
Thanks for your suggestion.  This sounds like it might work.  I did not write this component, we are using one that someone else wrote and posted on github.  Are you talking about the Properties() that is on the LoggingEvent object?  If so, there is a point in the code where I see the correct data in ThreadingContext.  I could get it out of there and put it into Properties.  However, I have not been able to find a way to iterate through the ThreadingContext because it does not have a GetEnumerator on it. How are you able to get data out of the threadContext?

From: chinhdo@gmail.com<ma...@gmail.com> [mailto:chinhdo@gmail.com<ma...@gmail.com>] On Behalf Of Chinh Do
Sent: Tuesday, July 30, 2013 4:28 PM
To: Log4NET Dev
Subject: Re: asynchronous logging

What I did my my AsyncAppender was to write thread specific data into loggingEvent.Properties in the main thread, just before I add the loggingEvent to a queue. Then you can use "%P{<PropertyName>}" in your log4net config section to get them later in the other thread.

My AsyncAppender was based on log4net AsyncAppender example (see http://logging.apache.org/log4net/release/example-apps.html). The log events sent to AsyncAppender are forwarded asynchronously to a list of attached appenders.

On Tue, Jul 30, 2013 at 2:31 PM, George Chung <ge...@glympse.com>> wrote:
If you authored your own AsynchronousAdoNetAppender that uses the new .NET async/await constructs, you could use the TPL library to wrap the ado.net<http://ado.net> async operations as a Task.

Then if you avoid calling ConfigureAwait(false), I'm pretty sure the completion routine will complete on the original ASP.NET<http://ASP.NET> request thread, in which case you'll have access to the original HttpContext that started the request.


On Tue, Jul 30, 2013 at 8:31 AM, Farrington, Linda <lf...@aclara.com>> wrote:

We are trying to log asynchronously using an asynchronousadonetappender inherited from adonetappender.   Logging standard properties seems to work fine, but custom properties do not.  I understand that this is because the asynchronous appender is logging the messages on another thread and we're storing the custom properties in the logicalthreadcontext (tried threadcontext = as well to no avail).  My question is this:  If I cannot use the threadcontext when running asynchronously, how should I pass custom properties into log4net.  Has anyone else done this?  Can anyone provide any suggestions?



Thanks in advance,



Linda








--
http://www.chinhdo.com



--
http://www.chinhdo.com




--
Dominik Psenner
## OpenPGP Key Signature #################################
# Key ID: B469318C                                       #
# Fingerprint: 558641995F7EC2D251354C3A49C7E3D1B469318C  #
##########################################################

Re: asynchronous logging

Posted by Dominik Psenner <dp...@gmail.com>.
Easy as that:

http://logging.apache.org/log4net/release/sdk/log4net.Util.ReadOnlyPropertiesDictionary.GetKeys.html


2013/7/31 Farrington, Linda <lf...@aclara.com>

>  Dominik,****
>
> ** **
>
> Seems obvious, but in our case, it’s not.   I am working within some apps
> that already exist that are calling this logging and trying to make these
> changes without disrupting them.    ****
>
> ** **
>
> The app calls the logging like so:****
>
> Push properties onto the threadcontext  (fill threadcontext.properties)***
> *
>
> Call Log.Debug  to log the error.  At this point, I am now in the append
> method in the asynchronous appender.  I have only the threading context to
> work with.  I don’t see an overload to pass additional properites.  So I am
> not sure how creating a separate properties dictionary would solve this.
> (I am new to log4net, so it’s possible I am missing the obvious)****
>
> ** **
>
> Thanks,****
>
> ** **
>
> Linda****
>
> ** **
>
> *From:* Dominik Psenner [mailto:dpsenner@gmail.com]
> *Sent:* Wednesday, July 31, 2013 9:25 AM
>
> *To:* Log4NET Dev
> *Subject:* Re: asynchronous logging****
>
>  ** **
>
> I may be pointing out the obvious, but why don't you let both applications
> write to the same key a collection which lets your third application
> determine which fields are being sent:
>
> string[] fields = Properties["fields"];
> foreach(string field in fields) {
>     string value = Properties[field];
> }
>
> Cheers
>
> On 07/31/2013 03:10 PM, Farrington, Linda wrote:****
>
> My data is coming to me in the ThreadingContext.Properties collection.
> There are about 10 elements in there.  I can’t seem to find a way to get
> the data out of this collection as there is no way to iterate it and I
> don’t know what the fields are named.  (We have two different applications
> and they pass in different data in the collection.****
>
>  ****
>
> *From:* chinhdo@gmail.com [mailto:chinhdo@gmail.com <ch...@gmail.com>] *On
> Behalf Of *Chinh Do
> *Sent:* Tuesday, July 30, 2013 10:07 PM
> *To:* Log4NET Dev
> *Subject:* Re: asynchronous logging****
>
>  ****
>
> Yes I was referring to log4net.Core.LoggingEvent.Properties.****
>
>  ****
>
> In my case, I know exactly what I need so I just had a few lines of code
> like this:****
>
>  ****
>
> // Implementation of IAppender.DoAppend****
>
> public void DoAppend(LoggingEvent loggingEvent) {****
>
>     loggingEvent.Properties["ThreadId"] =
> Thread.CurrentThread.ManagedThreadId.ToString();****
>
>     loggingEvent.Properties["MyUserId"] = ...****
>
>     loggingEvent.Properties["MySessionId"] = ...****
>
>     ...****
>
>     AddToQueue(loggingEvent);****
>
> }****
>
>  ****
>
>  ****
>
> On Tue, Jul 30, 2013 at 5:42 PM, Farrington, Linda <lf...@aclara.com>
> wrote:****
>
> Chinh Do,****
>
> Thanks for your suggestion.  This sounds like it might work.  I did not
> write this component, we are using one that someone else wrote and posted
> on github.  Are you talking about the Properties() that is on the
> LoggingEvent object?  If so, there is a point in the code where I see the
> correct data in ThreadingContext.  I could get it out of there and put it
> into Properties.  However, I have not been able to find a way to iterate
> through the ThreadingContext because it does not have a GetEnumerator on
> it. How are you able to get data out of the threadContext?****
>
>  ****
>
> *From:* chinhdo@gmail.com [mailto:chinhdo@gmail.com] *On Behalf Of *Chinh
> Do
> *Sent:* Tuesday, July 30, 2013 4:28 PM
> *To:* Log4NET Dev
> *Subject:* Re: asynchronous logging****
>
>  ****
>
> What I did my my AsyncAppender was to write thread specific data into
> loggingEvent.Properties in the main thread, just before I add the
> loggingEvent to a queue. Then you can use "%P{<PropertyName>}" in your
> log4net config section to get them later in the other thread.****
>
>  ****
>
> My AsyncAppender was based on log4net AsyncAppender example (see
> http://logging.apache.org/log4net/release/example-apps.html). The log
> events sent to AsyncAppender are forwarded asynchronously to a list of
> attached appenders.****
>
>  ****
>
> On Tue, Jul 30, 2013 at 2:31 PM, George Chung <ge...@glympse.com> wrote:*
> ***
>
> If you authored your own AsynchronousAdoNetAppender that uses the new .NET
> async/await constructs, you could use the TPL library to wrap the ado.netasync operations as a Task.
> ****
>
>  ****
>
> Then if you *avoid *calling ConfigureAwait(false), I'm pretty sure the
> completion routine will complete on the original ASP.NET request thread,
> in which case you'll have access to the original HttpContext that started
> the request.****
>
>  ****
>
>  ****
>
> On Tue, Jul 30, 2013 at 8:31 AM, Farrington, Linda <lf...@aclara.com>
> wrote:****
>
> We are trying to log asynchronously using an asynchronousadonetappender
> inherited from adonetappender.   Logging standard properties seems to work
> fine, but custom properties do not.  I understand that this is because the
> asynchronous appender is logging the messages on another thread and we're
> storing the custom properties in the logicalthreadcontext (tried
> threadcontext = as well to no avail).  My question is this:  If I cannot
> use the threadcontext when running asynchronously, how should I pass custom
> properties into log4net.  Has anyone else done this?  Can anyone provide
> any suggestions?****
>
>  ****
>
> Thanks in advance,****
>
>  ****
>
> Linda****
>
>  ****
>
>  ****
>
>  ****
>
>  ****
>
>
>
> ****
>
>  ****
>
> --
> http://www.chinhdo.com ** **
>
>
>
> ****
>
>  ****
>
> --
> http://www.chinhdo.com ****
>
> ** **
>



-- 
Dominik Psenner
## OpenPGP Key Signature #################################
# Key ID: B469318C                                       #
# Fingerprint: 558641995F7EC2D251354C3A49C7E3D1B469318C  #
##########################################################

RE: asynchronous logging

Posted by "Farrington, Linda" <lf...@aclara.com>.
Dominik,

Seems obvious, but in our case, it’s not.   I am working within some apps that already exist that are calling this logging and trying to make these changes without disrupting them.

The app calls the logging like so:
Push properties onto the threadcontext  (fill threadcontext.properties)
Call Log.Debug  to log the error.  At this point, I am now in the append method in the asynchronous appender.  I have only the threading context to work with.  I don’t see an overload to pass additional properites.  So I am not sure how creating a separate properties dictionary would solve this.  (I am new to log4net, so it’s possible I am missing the obvious)

Thanks,

Linda

From: Dominik Psenner [mailto:dpsenner@gmail.com]
Sent: Wednesday, July 31, 2013 9:25 AM
To: Log4NET Dev
Subject: Re: asynchronous logging

I may be pointing out the obvious, but why don't you let both applications write to the same key a collection which lets your third application determine which fields are being sent:

string[] fields = Properties["fields"];
foreach(string field in fields) {
    string value = Properties[field];
}

Cheers

On 07/31/2013 03:10 PM, Farrington, Linda wrote:
My data is coming to me in the ThreadingContext.Properties collection.  There are about 10 elements in there.  I can’t seem to find a way to get the data out of this collection as there is no way to iterate it and I don’t know what the fields are named.  (We have two different applications and they pass in different data in the collection.

From: chinhdo@gmail.com<ma...@gmail.com> [mailto:chinhdo@gmail.com] On Behalf Of Chinh Do
Sent: Tuesday, July 30, 2013 10:07 PM
To: Log4NET Dev
Subject: Re: asynchronous logging

Yes I was referring to log4net.Core.LoggingEvent.Properties.

In my case, I know exactly what I need so I just had a few lines of code like this:

// Implementation of IAppender.DoAppend
public void DoAppend(LoggingEvent loggingEvent) {
    loggingEvent.Properties["ThreadId"] = Thread.CurrentThread.ManagedThreadId.ToString();
    loggingEvent.Properties["MyUserId"] = ...
    loggingEvent.Properties["MySessionId"] = ...
    ...
    AddToQueue(loggingEvent);
}


On Tue, Jul 30, 2013 at 5:42 PM, Farrington, Linda <lf...@aclara.com>> wrote:
Chinh Do,
Thanks for your suggestion.  This sounds like it might work.  I did not write this component, we are using one that someone else wrote and posted on github.  Are you talking about the Properties() that is on the LoggingEvent object?  If so, there is a point in the code where I see the correct data in ThreadingContext.  I could get it out of there and put it into Properties.  However, I have not been able to find a way to iterate through the ThreadingContext because it does not have a GetEnumerator on it. How are you able to get data out of the threadContext?

From: chinhdo@gmail.com<ma...@gmail.com> [mailto:chinhdo@gmail.com<ma...@gmail.com>] On Behalf Of Chinh Do
Sent: Tuesday, July 30, 2013 4:28 PM
To: Log4NET Dev
Subject: Re: asynchronous logging

What I did my my AsyncAppender was to write thread specific data into loggingEvent.Properties in the main thread, just before I add the loggingEvent to a queue. Then you can use "%P{<PropertyName>}" in your log4net config section to get them later in the other thread.

My AsyncAppender was based on log4net AsyncAppender example (see http://logging.apache.org/log4net/release/example-apps.html). The log events sent to AsyncAppender are forwarded asynchronously to a list of attached appenders.

On Tue, Jul 30, 2013 at 2:31 PM, George Chung <ge...@glympse.com>> wrote:
If you authored your own AsynchronousAdoNetAppender that uses the new .NET async/await constructs, you could use the TPL library to wrap the ado.net<http://ado.net> async operations as a Task.

Then if you avoid calling ConfigureAwait(false), I'm pretty sure the completion routine will complete on the original ASP.NET<http://ASP.NET> request thread, in which case you'll have access to the original HttpContext that started the request.


On Tue, Jul 30, 2013 at 8:31 AM, Farrington, Linda <lf...@aclara.com>> wrote:

We are trying to log asynchronously using an asynchronousadonetappender inherited from adonetappender.   Logging standard properties seems to work fine, but custom properties do not.  I understand that this is because the asynchronous appender is logging the messages on another thread and we're storing the custom properties in the logicalthreadcontext (tried threadcontext = as well to no avail).  My question is this:  If I cannot use the threadcontext when running asynchronously, how should I pass custom properties into log4net.  Has anyone else done this?  Can anyone provide any suggestions?



Thanks in advance,



Linda








--
http://www.chinhdo.com



--
http://www.chinhdo.com


Re: asynchronous logging

Posted by Dominik Psenner <dp...@gmail.com>.
I may be pointing out the obvious, but why don't you let both 
applications write to the same key a collection which lets your third 
application determine which fields are being sent:

string[] fields = Properties["fields"];
foreach(string field in fields) {
     string value = Properties[field];
}

Cheers

On 07/31/2013 03:10 PM, Farrington, Linda wrote:
>
> My data is coming to me in the ThreadingContext.Properties 
> collection.  There are about 10 elements in there.  I can’t seem to 
> find a way to get the data out of this collection as there is no way 
> to iterate it and I don’t know what the fields are named.  (We have 
> two different applications and they pass in different data in the 
> collection.
>
> *From:*chinhdo@gmail.com [mailto:chinhdo@gmail.com] *On Behalf Of 
> *Chinh Do
> *Sent:* Tuesday, July 30, 2013 10:07 PM
> *To:* Log4NET Dev
> *Subject:* Re: asynchronous logging
>
> Yes I was referring to log4net.Core.LoggingEvent.Properties.
>
> In my case, I know exactly what I need so I just had a few lines of 
> code like this:
>
> // Implementation of IAppender.DoAppend
>
> public void DoAppend(LoggingEvent loggingEvent) {
>
>     loggingEvent.Properties["ThreadId"] = 
> Thread.CurrentThread.ManagedThreadId.ToString();
>
>     loggingEvent.Properties["MyUserId"] = ...
>
>     loggingEvent.Properties["MySessionId"] = ...
>
>     ...
>
>     AddToQueue(loggingEvent);
>
> }
>
> On Tue, Jul 30, 2013 at 5:42 PM, Farrington, Linda 
> <lfarrington@aclara.com <ma...@aclara.com>> wrote:
>
> Chinh Do,
>
> Thanks for your suggestion.  This sounds like it might work.  I did 
> not write this component, we are using one that someone else wrote and 
> posted on github. Are you talking about the Properties() that is on 
> the LoggingEvent object?  If so, there is a point in the code where I 
> see the correct data in ThreadingContext.  I could get it out of there 
> and put it into Properties.  However, I have not been able to find a 
> way to iterate through the ThreadingContext because it does not have a 
> GetEnumerator on it. How are you able to get data out of the 
> threadContext?
>
> *From:*chinhdo@gmail.com <ma...@gmail.com> 
> [mailto:chinhdo@gmail.com <ma...@gmail.com>] *On Behalf Of 
> *Chinh Do
> *Sent:* Tuesday, July 30, 2013 4:28 PM
> *To:* Log4NET Dev
> *Subject:* Re: asynchronous logging
>
> What I did my my AsyncAppender was to write thread specific data into 
> loggingEvent.Properties in the main thread, just before I add the 
> loggingEvent to a queue. Then you can use "%P{<PropertyName>}" in your 
> log4net config section to get them later in the other thread.
>
> My AsyncAppender was based on log4net AsyncAppender example (see 
> http://logging.apache.org/log4net/release/example-apps.html). The log 
> events sent to AsyncAppender are forwarded asynchronously to a list of 
> attached appenders.
>
> On Tue, Jul 30, 2013 at 2:31 PM, George Chung <george@glympse.com 
> <ma...@glympse.com>> wrote:
>
> If you authored your own AsynchronousAdoNetAppender that uses the new 
> .NET async/await constructs, you could use the TPL library to wrap the 
> ado.net <http://ado.net> async operations as a Task.
>
> Then if you *avoid *calling ConfigureAwait(false), I'm pretty sure the 
> completion routine will complete on the original ASP.NET 
> <http://ASP.NET> request thread, in which case you'll have access to 
> the original HttpContext that started the request.
>
> On Tue, Jul 30, 2013 at 8:31 AM, Farrington, Linda 
> <lfarrington@aclara.com <ma...@aclara.com>> wrote:
>
> We are trying to log asynchronously using an 
> asynchronousadonetappender inherited from adonetappender.   Logging 
> standard properties seems to work fine, but custom properties do not.  
> I understand that this is because the asynchronous appender is logging 
> the messages on another thread and we're storing the custom properties 
> in the logicalthreadcontext (tried threadcontext = as well to no 
> avail).  My question is this:  If I cannot use the threadcontext when 
> running asynchronously, how should I pass custom properties into 
> log4net.  Has anyone else done this?  Can anyone provide any suggestions?
>
> Thanks in advance,
>
> Linda
>
>
>
> -- 
> http://www.chinhdo.com
>
>
>
> -- 
> http://www.chinhdo.com
>


RE: asynchronous logging

Posted by "Farrington, Linda" <lf...@aclara.com>.
My data is coming to me in the ThreadingContext.Properties collection.  There are about 10 elements in there.  I can’t seem to find a way to get the data out of this collection as there is no way to iterate it and I don’t know what the fields are named.  (We have two different applications and they pass in different data in the collection.

From: chinhdo@gmail.com [mailto:chinhdo@gmail.com] On Behalf Of Chinh Do
Sent: Tuesday, July 30, 2013 10:07 PM
To: Log4NET Dev
Subject: Re: asynchronous logging

Yes I was referring to log4net.Core.LoggingEvent.Properties.

In my case, I know exactly what I need so I just had a few lines of code like this:

// Implementation of IAppender.DoAppend
public void DoAppend(LoggingEvent loggingEvent) {
    loggingEvent.Properties["ThreadId"] = Thread.CurrentThread.ManagedThreadId.ToString();
    loggingEvent.Properties["MyUserId"] = ...
    loggingEvent.Properties["MySessionId"] = ...
    ...
    AddToQueue(loggingEvent);
}


On Tue, Jul 30, 2013 at 5:42 PM, Farrington, Linda <lf...@aclara.com>> wrote:
Chinh Do,
Thanks for your suggestion.  This sounds like it might work.  I did not write this component, we are using one that someone else wrote and posted on github.  Are you talking about the Properties() that is on the LoggingEvent object?  If so, there is a point in the code where I see the correct data in ThreadingContext.  I could get it out of there and put it into Properties.  However, I have not been able to find a way to iterate through the ThreadingContext because it does not have a GetEnumerator on it. How are you able to get data out of the threadContext?

From: chinhdo@gmail.com<ma...@gmail.com> [mailto:chinhdo@gmail.com<ma...@gmail.com>] On Behalf Of Chinh Do
Sent: Tuesday, July 30, 2013 4:28 PM
To: Log4NET Dev
Subject: Re: asynchronous logging

What I did my my AsyncAppender was to write thread specific data into loggingEvent.Properties in the main thread, just before I add the loggingEvent to a queue. Then you can use "%P{<PropertyName>}" in your log4net config section to get them later in the other thread.

My AsyncAppender was based on log4net AsyncAppender example (see http://logging.apache.org/log4net/release/example-apps.html). The log events sent to AsyncAppender are forwarded asynchronously to a list of attached appenders.

On Tue, Jul 30, 2013 at 2:31 PM, George Chung <ge...@glympse.com>> wrote:
If you authored your own AsynchronousAdoNetAppender that uses the new .NET async/await constructs, you could use the TPL library to wrap the ado.net<http://ado.net> async operations as a Task.

Then if you avoid calling ConfigureAwait(false), I'm pretty sure the completion routine will complete on the original ASP.NET<http://ASP.NET> request thread, in which case you'll have access to the original HttpContext that started the request.


On Tue, Jul 30, 2013 at 8:31 AM, Farrington, Linda <lf...@aclara.com>> wrote:

We are trying to log asynchronously using an asynchronousadonetappender inherited from adonetappender.   Logging standard properties seems to work fine, but custom properties do not.  I understand that this is because the asynchronous appender is logging the messages on another thread and we're storing the custom properties in the logicalthreadcontext (tried threadcontext = as well to no avail).  My question is this:  If I cannot use the threadcontext when running asynchronously, how should I pass custom properties into log4net.  Has anyone else done this?  Can anyone provide any suggestions?



Thanks in advance,



Linda








--
http://www.chinhdo.com



--
http://www.chinhdo.com

Re: asynchronous logging

Posted by Chinh Do <cd...@vienxu.com>.
Yes I was referring to log4net.Core.LoggingEvent.Properties.

In my case, I know exactly what I need so I just had a few lines of code
like this:

// Implementation of IAppender.DoAppend
public void DoAppend(LoggingEvent loggingEvent) {
    loggingEvent.Properties["ThreadId"] =
Thread.CurrentThread.ManagedThreadId.ToString();
    loggingEvent.Properties["MyUserId"] = ...
    loggingEvent.Properties["MySessionId"] = ...
    ...
    AddToQueue(loggingEvent);
}



On Tue, Jul 30, 2013 at 5:42 PM, Farrington, Linda
<lf...@aclara.com>wrote:

>  Chinh Do,****
>
> Thanks for your suggestion.  This sounds like it might work.  I did not
> write this component, we are using one that someone else wrote and posted
> on github.  Are you talking about the Properties() that is on the
> LoggingEvent object?  If so, there is a point in the code where I see the
> correct data in ThreadingContext.  I could get it out of there and put it
> into Properties.  However, I have not been able to find a way to iterate
> through the ThreadingContext because it does not have a GetEnumerator on
> it. How are you able to get data out of the threadContext?****
>
> ** **
>
> *From:* chinhdo@gmail.com [mailto:chinhdo@gmail.com] *On Behalf Of *Chinh
> Do
> *Sent:* Tuesday, July 30, 2013 4:28 PM
> *To:* Log4NET Dev
> *Subject:* Re: asynchronous logging****
>
> ** **
>
> What I did my my AsyncAppender was to write thread specific data into
> loggingEvent.Properties in the main thread, just before I add the
> loggingEvent to a queue. Then you can use "%P{<PropertyName>}" in your
> log4net config section to get them later in the other thread.****
>
> ** **
>
> My AsyncAppender was based on log4net AsyncAppender example (see
> http://logging.apache.org/log4net/release/example-apps.html). The log
> events sent to AsyncAppender are forwarded asynchronously to a list of
> attached appenders.****
>
> ** **
>
> On Tue, Jul 30, 2013 at 2:31 PM, George Chung <ge...@glympse.com> wrote:*
> ***
>
> If you authored your own AsynchronousAdoNetAppender that uses the new .NET
> async/await constructs, you could use the TPL library to wrap the ado.netasync operations as a Task.
> ****
>
> ** **
>
> Then if you *avoid *calling ConfigureAwait(false), I'm pretty sure the
> completion routine will complete on the original ASP.NET request thread,
> in which case you'll have access to the original HttpContext that started
> the request.****
>
> ** **
>
> ** **
>
> On Tue, Jul 30, 2013 at 8:31 AM, Farrington, Linda <lf...@aclara.com>
> wrote:****
>
> We are trying to log asynchronously using an asynchronousadonetappender
> inherited from adonetappender.   Logging standard properties seems to work
> fine, but custom properties do not.  I understand that this is because the
> asynchronous appender is logging the messages on another thread and we're
> storing the custom properties in the logicalthreadcontext (tried
> threadcontext = as well to no avail).  My question is this:  If I cannot
> use the threadcontext when running asynchronously, how should I pass custom
> properties into log4net.  Has anyone else done this?  Can anyone provide
> any suggestions?****
>
>  ****
>
> Thanks in advance,****
>
>  ****
>
> Linda****
>
>  ****
>
>  ****
>
>  ****
>
> ** **
>
>
>
> ****
>
> ** **
>
> --
> http://www.chinhdo.com ****
>



-- 
http://www.chinhdo.com

RE: asynchronous logging

Posted by "Farrington, Linda" <lf...@aclara.com>.
Chinh Do,
Thanks for your suggestion.  This sounds like it might work.  I did not write this component, we are using one that someone else wrote and posted on github.  Are you talking about the Properties() that is on the LoggingEvent object?  If so, there is a point in the code where I see the correct data in ThreadingContext.  I could get it out of there and put it into Properties.  However, I have not been able to find a way to iterate through the ThreadingContext because it does not have a GetEnumerator on it. How are you able to get data out of the threadContext?

From: chinhdo@gmail.com [mailto:chinhdo@gmail.com] On Behalf Of Chinh Do
Sent: Tuesday, July 30, 2013 4:28 PM
To: Log4NET Dev
Subject: Re: asynchronous logging

What I did my my AsyncAppender was to write thread specific data into loggingEvent.Properties in the main thread, just before I add the loggingEvent to a queue. Then you can use "%P{<PropertyName>}" in your log4net config section to get them later in the other thread.

My AsyncAppender was based on log4net AsyncAppender example (see http://logging.apache.org/log4net/release/example-apps.html). The log events sent to AsyncAppender are forwarded asynchronously to a list of attached appenders.

On Tue, Jul 30, 2013 at 2:31 PM, George Chung <ge...@glympse.com>> wrote:
If you authored your own AsynchronousAdoNetAppender that uses the new .NET async/await constructs, you could use the TPL library to wrap the ado.net<http://ado.net> async operations as a Task.

Then if you avoid calling ConfigureAwait(false), I'm pretty sure the completion routine will complete on the original ASP.NET<http://ASP.NET> request thread, in which case you'll have access to the original HttpContext that started the request.


On Tue, Jul 30, 2013 at 8:31 AM, Farrington, Linda <lf...@aclara.com>> wrote:

We are trying to log asynchronously using an asynchronousadonetappender inherited from adonetappender.   Logging standard properties seems to work fine, but custom properties do not.  I understand that this is because the asynchronous appender is logging the messages on another thread and we're storing the custom properties in the logicalthreadcontext (tried threadcontext = as well to no avail).  My question is this:  If I cannot use the threadcontext when running asynchronously, how should I pass custom properties into log4net.  Has anyone else done this?  Can anyone provide any suggestions?



Thanks in advance,



Linda








--
http://www.chinhdo.com

Re: asynchronous logging

Posted by Chinh Do <cd...@vienxu.com>.
What I did my my AsyncAppender was to write thread specific data into
loggingEvent.Properties in the main thread, just before I add the
loggingEvent to a queue. Then you can use "%P{<PropertyName>}" in your
log4net config section to get them later in the other thread.

My AsyncAppender was based on log4net AsyncAppender example (see
http://logging.apache.org/log4net/release/example-apps.html). The log
events sent to AsyncAppender are forwarded asynchronously to a list of
attached appenders.

On Tue, Jul 30, 2013 at 2:31 PM, George Chung <ge...@glympse.com> wrote:

> If you authored your own AsynchronousAdoNetAppender that uses the new .NET
> async/await constructs, you could use the TPL library to wrap the ado.netasync operations as a Task.
>
> Then if you *avoid *calling ConfigureAwait(false), I'm pretty sure the
> completion routine will complete on the original ASP.NET request thread,
> in which case you'll have access to the original HttpContext that started
> the request.
>
>
>
> On Tue, Jul 30, 2013 at 8:31 AM, Farrington, Linda <lfarrington@aclara.com
> > wrote:
>
>>  We are trying to log asynchronously using an asynchronousadonetappender
>> inherited from adonetappender.   Logging standard properties seems to work
>> fine, but custom properties do not.  I understand that this is because the
>> asynchronous appender is logging the messages on another thread and we're
>> storing the custom properties in the logicalthreadcontext (tried
>> threadcontext = as well to no avail).  My question is this:  If I cannot
>> use the threadcontext when running asynchronously, how should I pass custom
>> properties into log4net.  Has anyone else done this?  Can anyone provide
>> any suggestions?****
>>
>> ** **
>>
>> Thanks in advance,****
>>
>> ** **
>>
>> Linda****
>>
>> ** **
>>
>> ** **
>>
>> ** **
>>
>
>


-- 
http://www.chinhdo.com

Re: asynchronous logging

Posted by George Chung <ge...@glympse.com>.
If you authored your own AsynchronousAdoNetAppender that uses the new .NET
async/await constructs, you could use the TPL library to wrap the
ado.netasync operations as a Task.

Then if you *avoid *calling ConfigureAwait(false), I'm pretty sure the
completion routine will complete on the original ASP.NET request thread, in
which case you'll have access to the original HttpContext that started the
request.



On Tue, Jul 30, 2013 at 8:31 AM, Farrington, Linda
<lf...@aclara.com>wrote:

>  We are trying to log asynchronously using an asynchronousadonetappender
> inherited from adonetappender.   Logging standard properties seems to work
> fine, but custom properties do not.  I understand that this is because the
> asynchronous appender is logging the messages on another thread and we're
> storing the custom properties in the logicalthreadcontext (tried
> threadcontext = as well to no avail).  My question is this:  If I cannot
> use the threadcontext when running asynchronously, how should I pass custom
> properties into log4net.  Has anyone else done this?  Can anyone provide
> any suggestions?****
>
> ** **
>
> Thanks in advance,****
>
> ** **
>
> Linda****
>
> ** **
>
> ** **
>
> ** **
>