2

Here's my code:

    Crashes.TrackError(ex,
       new Dictionary<string, string> {
            {"RunQuery", "Exception"},
            {"sql", s },
            {"Device Model", DeviceInfo.Model },
            {"Exception", ex.ToString()}
       });

Everything works but I find that Appcenter limits the length of the parameters to 125 characters so it's useless for me as I can never see all of the sql or the ex string.

Has anyone found a way to get around this?

Alan2
  • 23,493
  • 79
  • 256
  • 450
  • 2
    Why would you want to have the `ex.ToString()` if you already get the full exception by adding the `ex` as a first parameter? Does that not give you all the info you need? Unless you're getting creative and split the message into 125 char chunks and add that as new parameters each time, I don't think there is any way around it. I'm pretty sure there is also a limit on the number of parameters, so that will also only get you so far. – Gerald Versluis Dec 15 '19 at 09:58

1 Answers1

1

I ran into the same problem. My solution was to break my string into groups of 125 character strings and iterate through while logging. I chatted with AppCenter support. They have no way of extending this length currently.

Here is a scrubbed version of my code:

var tokenChunks = LoggingHelper.SplitBy(extremelyLongString, 120);
string title = "Long string here";
var props = new Dictionary<string, string>();
int item = 0;
foreach(string chunk in tokenChunks)
{
    string chunkIndex = string.Format("item: {0}", item++);
    props.Add(chunkIndex, chunk);
}
Analytics.TrackEvent(title, props);

Where the LoggingHelper class is:

public static class LoggingHelper
{
    public static IEnumerable<string> SplitBy(this string str, int chunkLength)
    {
        if (String.IsNullOrEmpty(str)) throw new ArgumentException();
        if (chunkLength < 1) throw new ArgumentException();

        for (int i = 0; i < str.Length; i += chunkLength)
        {
            if (chunkLength + i > str.Length)
                chunkLength = str.Length - i;

            yield return str.Substring(i, chunkLength);
        }
    }
}

I should give credit to this post https://stackoverflow.com/a/8944374/117995 by @oleksii for the SplitBy method.

Blanthor
  • 2,568
  • 8
  • 48
  • 66