DebugTextWriter on Portable causes each character to be written on its own line #2321

Closed
Redth opened this Issue Jul 22, 2013 · 14 comments

Projects

None yet

5 participants

@Redth
Redth commented Jul 22, 2013

Consider this code:

https://github.com/SignalR/SignalR/blob/master/src/Microsoft.AspNet.SignalR.Client/Connection.cs#L786

It's causing (at least on xamarin) the traces to be written to a newline for each character (annoying).

You must implement the Write(char value) override for PCL, so need a way to Debug.Write(...) basically.

One ugly approach would be:

#if NETFX_CORE || PORTABLE
StringBuilder buffer = new StringBuilder();

public override void Write(char value)
{
  lock (buffer)
  {
    buffer.Append (value);

    if (buffer.ToString ().EndsWith (NewLine))
    {
      WriteLine (buffer.ToString ().Trim ());
      buffer.Clear ();
    }
  }
}
#endif

Probably a better way...

@halter73 halter73 was assigned Jul 23, 2013
@davidfowl
Member

@halter73 Giving this one to you.

@davidfowl
Member

@gustavo-armenta Can you reproduce this?

@abnanda1 abnanda1 was assigned Jul 29, 2013
@abnanda1
abnanda1 commented Aug 7, 2013

@Redth which window in Xamarin do you see the traces from the default DebugWriter? Also, I am assuming the problem you mentioned is to do with the traces that we output?

@Redth
Redth commented Aug 7, 2013

@abnanda1 in the Application Output window (on Xamarin.Android, at least)... Yes, I'm speaking about the traces that SignalR outputs... It looks like the pull request #2396 which @abnanda1 provided would solve this, according to my findings while debugging. It's similar to the approach I had proposed...

@davidfowl
Member

@Redth can you verify the fix?

@Redth
Redth commented Aug 8, 2013

@davidfowl confirmed, the trace now outputs correctly for portable (including Xamarin.Android).

@abnanda1
abnanda1 commented Aug 8, 2013

@Redth that's great. I have a quick question - how exactly are you setting-up our DebugWriter to output to Application Output. For our other clients we modify the App.config to set that up but there isn't anything like that in Android and iOS clients. I also noticed that TextWriterTraceListener and DefaultTraceListener are not supported in portable or mono so you can't add the listeners programmatically.

@Redth
Redth commented Aug 8, 2013

@abnanda1 I'm not doing anything at all, it just happens as is by default...

@abnanda1
abnanda1 commented Aug 8, 2013

@Redth that's interesting - I am not seeing the logs in the Application Output with our sample iOS app. Can you put-up a zip file containing your sample - I want to verify the thing once at our end as well.

@Redth
Redth commented Aug 10, 2013

@abnanda1 I was completely forgetting the fact that I'm running this using the JabbR.Client library. I'm guessing that it sets up the TraceWriter... Not too familiar with the internals of that, but sorry for leaving that out.

@davidfowl
Member

@abnanda1 why is this marked as blocked? @Redth verified the fix.

@davidfowl
Member
@davidfowl
Member

Marking this as done. @gustavo-armenta, @Redth verified that the fix worked.

@gustavo-armenta

tested using DebugTextWriter directly in a WinStore app

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment