Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ProtocolLogger: Shouldn't the caller decide when to dispose the log stream #506

Closed
axunonb opened this issue May 8, 2017 · 7 comments
Closed
Labels
enhancement New feature or request

Comments

@axunonb
Copy link

axunonb commented May 8, 2017

Jeff
Shouldn't the caller decide when the stream used for ProtocolLogger should be disposed?
Currently, disposing SmtpClient also disposes the log stream.
Simplified code:

var logStream = new MemoryStream();
var smtpClient = new SmtpClient(new MailKit.ProtocolLogger(logStream));

smtpClient.Connect("smtp.1and1.com", 25);
smtpClient.Dispose();

// Logic for taking care of the log is in a different part of the code
logStream.Position = 0;  // raising ObjectDisposedException
var reader = new StreamReader(logStream);
var log = reader.ReadToEnd();

Cheers,
Norbert

@jstedfast jstedfast added the enhancement New feature or request label May 9, 2017
@jstedfast
Copy link
Owner

Not really, no, because the protocol logger disposes the stream when the .ctor takes a filename parameter.

I can add a leaveOpen param for the Stream .ctor, though.

How is that?

jstedfast added a commit that referenced this issue May 9, 2017
@axunonb
Copy link
Author

axunonb commented May 9, 2017

That is perfect for the use case I described.
Thanks for quick response and even implementation!

@grokky1
Copy link

grokky1 commented Jun 29, 2017

@jstedfast Yeah this is exactly what I need too, but it isn't included in the latest nuget. 😢 When do you expect the next release to be?

@jstedfast
Copy link
Owner

waiting on people to get back to me with info needed to fix some reported bugs. once I get that info and fix the bugs, I'll make a release. Hoping it comes soon.

@grokky1
Copy link

grokky1 commented Jun 29, 2017

How did @axunonb use this new code if it hasn't been released ❓

@jstedfast
Copy link
Owner

He probably used the source code?

@grokky1
Copy link

grokky1 commented Jun 29, 2017

Oh wow then he was more desperate than me 😃 I'll wait for the nuget!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants