Generating unique ID of an exception
Stack trace

I think you shouldn't work with the stack string but retrieve the stack and go through each frame yourself. I find it would make the analysis more reliable and you could get the information you need without extracting it from the string because you would have direct access to each part.

private static IEnumerable&lt;dynamic&gt; GetStackTrace(this Exception exception)
{
    var stackTrace = new StackTrace(exception, true);
    var stackFrames = stackTrace.GetFrames();
    var result = stackFrames?.Select(sf =&gt; new
    {
        Caller = (sf.GetMethod() as MethodInfo)?.ToShortString() ?? string.Empty,
        FileName = Path.GetFileName(sf.GetFileName()),
        LineNumber = sf.GetFileLineNumber(),
    });
}


This snippet comes from my Exception prettyfier.



Other suggestions

It would be a good idea to split this method into three or four methods.


the first one gets you the information you need from the stack - you could implement it either based on the string or on the raw stack trace
the second one would encode the data as Base64String
the third and last one would clean-up or encode the string generated by the second one
the fourth could be a helper encapsulating the three other methods


Example:

var ex.ToExceptionId()


where

public static string ToExceptionId(this Exception ex)
{
    return ex.GetStackTrace().ToBase64String().EncodeBase64String();
}


Now you can test and maintain each part of the exception id creation separately.