You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4net-user@logging.apache.org by Charles Johnson <cj...@cehjohnson.uklinux.net> on 2005/06/12 01:08:46 UTC

Buffer flushing problem?

I'm experiencing a problem that varies each time i run my app. Sometimes
it reads all the content, sometimes just the top part. I don't want to
prejudge things, but perhaps someone could comment on this question i
posted?

http://www.experts-exchange.com/Programming/Programming_Languages/C_Sharp/Q_21454942.html



Re: Buffer flushing problem?

Posted by Charles Johnson <cj...@cehjohnson.uklinux.net>.
Well Ron, you may have seen my last post, where it states i can make the
program fail in the way i mentioned earlier *without* the logging api,
merely by running two copies of the program simultaneously, although the
errors are rarer. The fact that they occur at all is significant though.
Still testing - and shall probably test in the way you mentioned too.

CJ

Ron Grabowski wrote:

>By simpler solution, I mean this 10 line snippet:
>
>HttpWebRequest request =
>(HttpWebRequest)WebRequest.Create("http://www.apache.org");
>HttpWebResponse response = (HttpWebResponse)request.GetResponse();
>Stream responseStream = response.GetResponseStream();
>using (StreamReader streamReader = new StreamReader(responseStream))
>{
> while (streamReader.Peek() >= 0) 
> {
>  log.Debug("streamReader.ReadLine(): " + streamReader.ReadLine());
> }
>}
>
>Have you verified that code like that works as expected before trying
>to implement a more complex pattern? Are you able to walk through your
>code in a debugger? If so, is the program executed as you expected? If
>you replace calls to log4net with Console.WriteLine do all messages
>appear correctly?
>
>--- Charles Johnson <cj...@cehjohnson.uklinux.net> wrote:
>
>  
>
>>It looks like you're requesting a webpage
>>then you want to iterate through each line in the file looking for
>>information.
>>    
>>
>>That's correct (as the link describes)
>>
>>    
>>
>>>>There's got to be a simpler solution than the one you came up with
>>>>        
>>>>
>>What's not simple about it? Perhaps you're referring to the use of
>>the Observer pattern? Admittedly it's slightly misleading in this
>>case since the fact that everything is presented in the same
>>compilation unit negates the benefit of loose coupling afforded by
>>using this pattern, but this is for *testing* purposes only - the
>>observer would be in a different unit later.
>>
>>    
>>
>>>>I suspect the problems you're experiencing are coming from
>>>>        
>>>>
>>theover-complication of reading a Stream.
>>
>>Not sure about this. Am at the moment testing it by eliminating all
>>logging to see if i can reproduce the effect of varying numbers of
>>lines being read or returned.
>>
>>CJ
>>
>>
>>
>>Ron Grabowski wrote:
>>
>>    
>>
>>>What are you trying to do? It looks like you're requesting a webpage
>>>then you want to iterate through each line in the file looking for
>>>information. There's got to be a simpler solution than the one you
>>>      
>>>
>>came
>>    
>>
>>>up with. I suspect the problems you're experiencing are coming from
>>>      
>>>
>>the
>>    
>>
>>>over-complication of reading a Stream. What exactly is your log4net
>>>question?
>>>
>>>--- Charles Johnson <cj...@cehjohnson.uklinux.net> wrote:
>>>
>>> 
>>>
>>>      
>>>
>>>>I'm experiencing a problem that varies each time i run my app.
>>>>Sometimes
>>>>it reads all the content, sometimes just the top part. I don't want
>>>>to
>>>>prejudge things, but perhaps someone could comment on this question
>>>>        
>>>>
>>i
>>    
>>
>>>>posted?
>>>>
>>>>
>>>>   
>>>>
>>>>        
>>>>
>>http://www.experts-exchange.com/Programming/Programming_Languages/C_Sharp/Q_21454942.html
>>    
>>
>>> 
>>>
>>>      
>>>
>>>>   
>>>>
>>>>        
>>>>
>>> 
>>>
>>>      
>>>
>
>
>  
>

Re: Buffer flushing problem?

Posted by Ron Grabowski <ro...@yahoo.com>.
By simpler solution, I mean this 10 line snippet:

HttpWebRequest request =
(HttpWebRequest)WebRequest.Create("http://www.apache.org");
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream responseStream = response.GetResponseStream();
using (StreamReader streamReader = new StreamReader(responseStream))
{
 while (streamReader.Peek() >= 0) 
 {
  log.Debug("streamReader.ReadLine(): " + streamReader.ReadLine());
 }
}

Have you verified that code like that works as expected before trying
to implement a more complex pattern? Are you able to walk through your
code in a debugger? If so, is the program executed as you expected? If
you replace calls to log4net with Console.WriteLine do all messages
appear correctly?

--- Charles Johnson <cj...@cehjohnson.uklinux.net> wrote:

> >>
> It looks like you're requesting a webpage
> then you want to iterate through each line in the file looking for
> information.
> >>
> 
> That's correct (as the link describes)
> 
> >>There's got to be a simpler solution than the one you came up with
> 
> What's not simple about it? Perhaps you're referring to the use of
> the Observer pattern? Admittedly it's slightly misleading in this
> case since the fact that everything is presented in the same
> compilation unit negates the benefit of loose coupling afforded by
> using this pattern, but this is for *testing* purposes only - the
> observer would be in a different unit later.
> 
> >>I suspect the problems you're experiencing are coming from
> theover-complication of reading a Stream.
> 
> Not sure about this. Am at the moment testing it by eliminating all
> logging to see if i can reproduce the effect of varying numbers of
> lines being read or returned.
> 
> CJ
> 
> 
> 
> Ron Grabowski wrote:
> 
> >What are you trying to do? It looks like you're requesting a webpage
> >then you want to iterate through each line in the file looking for
> >information. There's got to be a simpler solution than the one you
> came
> >up with. I suspect the problems you're experiencing are coming from
> the
> >over-complication of reading a Stream. What exactly is your log4net
> >question?
> >
> >--- Charles Johnson <cj...@cehjohnson.uklinux.net> wrote:
> >
> >  
> >
> >>I'm experiencing a problem that varies each time i run my app.
> >>Sometimes
> >>it reads all the content, sometimes just the top part. I don't want
> >>to
> >>prejudge things, but perhaps someone could comment on this question
> i
> >>posted?
> >>
> >>
> >>    
> >>
>
>http://www.experts-exchange.com/Programming/Programming_Languages/C_Sharp/Q_21454942.html
> >  
> >
> >>    
> >>
> >
> >
> >  
> >
> 


Re: Buffer flushing problem?

Posted by Charles Johnson <cj...@cehjohnson.uklinux.net>.
>>
It looks like you're requesting a webpage
then you want to iterate through each line in the file looking for
information.
>>

That's correct (as the link describes)

>>There's got to be a simpler solution than the one you came up with

What's not simple about it? Perhaps you're referring to the use of the Observer pattern? Admittedly it's slightly misleading in this case since the fact that everything is presented in the same compilation unit negates the benefit of loose coupling afforded by using this pattern, but this is for *testing* purposes only - the observer would be in a different unit later.

>>I suspect the problems you're experiencing are coming from theover-complication of reading a Stream.

Not sure about this. Am at the moment testing it by eliminating all logging to see if i can reproduce the effect of varying numbers of lines being read or returned.

CJ



Ron Grabowski wrote:

>What are you trying to do? It looks like you're requesting a webpage
>then you want to iterate through each line in the file looking for
>information. There's got to be a simpler solution than the one you came
>up with. I suspect the problems you're experiencing are coming from the
>over-complication of reading a Stream. What exactly is your log4net
>question?
>
>--- Charles Johnson <cj...@cehjohnson.uklinux.net> wrote:
>
>  
>
>>I'm experiencing a problem that varies each time i run my app.
>>Sometimes
>>it reads all the content, sometimes just the top part. I don't want
>>to
>>prejudge things, but perhaps someone could comment on this question i
>>posted?
>>
>>
>>    
>>
>http://www.experts-exchange.com/Programming/Programming_Languages/C_Sharp/Q_21454942.html
>  
>
>>    
>>
>
>
>  
>

Re: Buffer flushing problem?

Posted by Charles Johnson <cj...@cehjohnson.uklinux.net>.
FYI, taking out the log4net calls, i can't reproduce the phenomenon of
the program failing to read the whole page. But - and this is
interesting - if i start up 2 programs, then one of them will sometimes
fail to read the whole page.

CJ

Ron Grabowski wrote:

>What are you trying to do? It looks like you're requesting a webpage
>then you want to iterate through each line in the file looking for
>information. There's got to be a simpler solution than the one you came
>up with. I suspect the problems you're experiencing are coming from the
>over-complication of reading a Stream. What exactly is your log4net
>question?
>
>--- Charles Johnson <cj...@cehjohnson.uklinux.net> wrote:
>
>  
>
>>I'm experiencing a problem that varies each time i run my app.
>>Sometimes
>>it reads all the content, sometimes just the top part. I don't want
>>to
>>prejudge things, but perhaps someone could comment on this question i
>>posted?
>>
>>
>>    
>>
>http://www.experts-exchange.com/Programming/Programming_Languages/C_Sharp/Q_21454942.html
>  
>
>>
>>    
>>
>
>
>  
>

Re: Buffer flushing problem?

Posted by Ron Grabowski <ro...@yahoo.com>.
What are you trying to do? It looks like you're requesting a webpage
then you want to iterate through each line in the file looking for
information. There's got to be a simpler solution than the one you came
up with. I suspect the problems you're experiencing are coming from the
over-complication of reading a Stream. What exactly is your log4net
question?

--- Charles Johnson <cj...@cehjohnson.uklinux.net> wrote:

> I'm experiencing a problem that varies each time i run my app.
> Sometimes
> it reads all the content, sometimes just the top part. I don't want
> to
> prejudge things, but perhaps someone could comment on this question i
> posted?
> 
>
http://www.experts-exchange.com/Programming/Programming_Languages/C_Sharp/Q_21454942.html
> 
> 
>