streams

C

csharpula csharp

Hello,

I have the following problem. I am writing to 2 files with stream writer
(one is the main log and other is the log for specific run) and in the
end of my application run I see that the writing to the main log sttoped
but the other log is ok (all of the data inside). I am not closing one
of the streams in the middle - what other reason can cause it?

Thanks
 
A

Arne Vajhøj

csharpula said:
I have the following problem. I am writing to 2 files with stream writer
(one is the main log and other is the log for specific run) and in the
end of my application run I see that the writing to the main log sttoped
but the other log is ok (all of the data inside). I am not closing one
of the streams in the middle - what other reason can cause it?

Do you close both of them properly?

Arne
 
A

Arne Vajhøj

csharpula said:
I have the following problem. I am writing to 2 files with stream writer
(one is the main log and other is the log for specific run) and in the
end of my application run I see that the writing to the main log sttoped
but the other log is ok (all of the data inside). I am not closing one
of the streams in the middle - what other reason can cause it?

Do you close both of them properly?

Arne
 
R

Ross

Have you tried wrapping both Stream methods and calling them when necessary?
It may be worthwhile adding try, catch and finally to each method too so
even if a unhandled exception is thrown, you can (finally) close the Stream
writer.
 
R

Ross

Have you tried wrapping both Stream methods and calling them when necessary?
It may be worthwhile adding try, catch and finally to each method too so
even if a unhandled exception is thrown, you can (finally) close the Stream
writer.
 
R

Ratnesh Maurya

Hello,

I have the following problem. I am writing to 2 files with stream writer
(one is the main log and other is the log for specific run) and in the
end of my application run I see that the writing to the main log sttoped
but the other log is ok (all of the data inside). I am not closing one
of the streams in the middle  - what other reason can cause it?

Thanks

*** Sent via Developersdexhttp://www.developersdex.com***

Why dont you use MS Enterprise Library Logging block for logging. It
makes your life easier by taking care of stream and all.
Its easy and clean. Trust me, give a try. :)

Cheers,
-Ratnesh
S7 Software
 
R

Ratnesh Maurya

Hello,

I have the following problem. I am writing to 2 files with stream writer
(one is the main log and other is the log for specific run) and in the
end of my application run I see that the writing to the main log sttoped
but the other log is ok (all of the data inside). I am not closing one
of the streams in the middle  - what other reason can cause it?

Thanks

*** Sent via Developersdexhttp://www.developersdex.com***

Why dont you use MS Enterprise Library Logging block for logging. It
makes your life easier by taking care of stream and all.
Its easy and clean. Trust me, give a try. :)

Cheers,
-Ratnesh
S7 Software
 
C

csharpula csharp

Hello,

It seems like stream.Flush() solving this. But the question is why do I
need to do Flush in order to update the file content? How can I avoid
doing it and see an updated file ?
 
C

csharpula csharp

Hello,

It seems like stream.Flush() solving this. But the question is why do I
need to do Flush in order to update the file content? How can I avoid
doing it and see an updated file ?
 
R

Ratnesh Maurya

Hello,

It seems like stream.Flush() solving this. But the question is why do I
need to do Flush in order to update the file content? How can I avoid
doing it and see an updated file ?

*** Sent via Developersdexhttp://www.developersdex.com***

Hi there,

u can do it by setting AutoFlush property to true.

but it always better to use some logging tool. log4n or Ent. Lib. Give
a try it is more cleaner and better way to do it :)

Cheers,
-Ratnesh Maurya
S7 Software Solutions
"Where Migration Meets Innovation"
 
R

Ratnesh Maurya

Hello,

It seems like stream.Flush() solving this. But the question is why do I
need to do Flush in order to update the file content? How can I avoid
doing it and see an updated file ?

*** Sent via Developersdexhttp://www.developersdex.com***

Hi there,

u can do it by setting AutoFlush property to true.

but it always better to use some logging tool. log4n or Ent. Lib. Give
a try it is more cleaner and better way to do it :)

Cheers,
-Ratnesh Maurya
S7 Software Solutions
"Where Migration Meets Innovation"
 
R

Ratnesh Maurya

But why the AutoFlush is not automatically set to true?

thanks!

*** Sent via Developersdexhttp://www.developersdex.com***

Its because... its addition work. Streams use internal buffer to store
data, which is faster.
once we call flush or close stream the data stored in buffer goes to
original location.

It is advised to not to set autoflush to true unless you the uotput of
stream is used like live feed or smthng. For instance Console.write
also writes to a stream where autoflush is true.

For normal operations u should use autoflush=false and use Flush after
some operations like when a transaction is complete so that you know
it is not being called too often, for performance purpose.

Cheers,
-Ratnesh
S7 Software
"Where migration meets innovation"
 
R

Ratnesh Maurya

But why the AutoFlush is not automatically set to true?

thanks!

*** Sent via Developersdexhttp://www.developersdex.com***

Its because... its addition work. Streams use internal buffer to store
data, which is faster.
once we call flush or close stream the data stored in buffer goes to
original location.

It is advised to not to set autoflush to true unless you the uotput of
stream is used like live feed or smthng. For instance Console.write
also writes to a stream where autoflush is true.

For normal operations u should use autoflush=false and use Flush after
some operations like when a transaction is complete so that you know
it is not being called too often, for performance purpose.

Cheers,
-Ratnesh
S7 Software
"Where migration meets innovation"
 
P

Peter

Ratnesh said:
Why dont you use MS Enterprise Library Logging block for logging. It
makes your life easier by taking care of stream and all.
Its easy and clean. Trust me, give a try. :)

Would you really recommend Enterprise Library's logging over for
example Log4Net?

You can also use "common logging" by the way, and then you can defer
the choice of exactly what concrete logging tool you use till
deploy/configuration time.

/Peter
 
P

Peter

Ratnesh said:
Why dont you use MS Enterprise Library Logging block for logging. It
makes your life easier by taking care of stream and all.
Its easy and clean. Trust me, give a try. :)

Would you really recommend Enterprise Library's logging over for
example Log4Net?

You can also use "common logging" by the way, and then you can defer
the choice of exactly what concrete logging tool you use till
deploy/configuration time.

/Peter
 
R

Ratnesh Maurya

Would you really recommend Enterprise Library's logging over for
example Log4Net?

You can also use "common logging" by the way, and then you can defer
the choice of exactly what concrete logging tool you use till
deploy/configuration time.

/Peter

Hi Peter,

I dont have that much insight about various tools as of now, so I
cannot really say which is better. And I never mentioned that Ent.
Lib. is better or vice-versa. I will think about this for sure and
reply later. Do you have some idea which is better to use for
beginners?
What I was trying to convey is use some logging tool so you wont have
worry about streams and all. Also as you know is more structured and
configurable.
You enable/disable logging or level of logging without even touching
the code.

Nothing related to performance, but I personally like Ent. Lib as it
has many other things in addition to logging such as Exception
Handling, Security, etc. and it has a tool Ent.Lib console which makes
it easy to configure/change/setup.

Cheers,
-Ratnesh
S7 Software Solutions
"Where Migration Meets Innovation"
 
R

Ratnesh Maurya

Would you really recommend Enterprise Library's logging over for
example Log4Net?

You can also use "common logging" by the way, and then you can defer
the choice of exactly what concrete logging tool you use till
deploy/configuration time.

/Peter

Hi Peter,

I dont have that much insight about various tools as of now, so I
cannot really say which is better. And I never mentioned that Ent.
Lib. is better or vice-versa. I will think about this for sure and
reply later. Do you have some idea which is better to use for
beginners?
What I was trying to convey is use some logging tool so you wont have
worry about streams and all. Also as you know is more structured and
configurable.
You enable/disable logging or level of logging without even touching
the code.

Nothing related to performance, but I personally like Ent. Lib as it
has many other things in addition to logging such as Exception
Handling, Security, etc. and it has a tool Ent.Lib console which makes
it easy to configure/change/setup.

Cheers,
-Ratnesh
S7 Software Solutions
"Where Migration Meets Innovation"
 
R

Ratnesh Maurya

Would you really recommend Enterprise Library's logging over for
example Log4Net?

You can also use "common logging" by the way, and then you can defer
the choice of exactly what concrete logging tool you use till
deploy/configuration time.

/Peter

Hi Peter,

I dont have that much insight about various tools as of now, so I
cannot really say which is better. And I never mentioned that Ent.
Lib. is better or vice-versa. I will think about this for sure and
reply later. Do you have some idea which is better to use for
beginners?
What I was trying to convey is use some logging tool so you wont have
worry about streams and all. Also as you know is more structured and
configurable.
You enable/disable logging or level of logging without even touching
the code.

Nothing related to performance, but I personally like Ent. Lib as it
has many other things in addition to logging such as Exception
Handling, Security, etc. and it has a tool Ent.Lib console which makes
it easy to configure/change/setup.

Cheers,
-Ratnesh
S7 Software Solutions
"Where Migration Meets Innovation"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top