exceptionless / Exceptionless.Net

Exceptionless clients for the .NET platform
https://exceptionless.com
Other
551 stars 142 forks source link

Issue with commit log in DispatcherUnhandledException event #287

Closed q812143836 closed 1 year ago

q812143836 commented 1 year ago
      [Command]
        public void Test()
        {
            try
            {
                int.Parse("asdfasdf");
            }
            catch (Exception e)
            {
                e.ToExceptionless()
                .SetUserIdentity(ServiceCloud.Instance.User?.UserId.ToString(), ServiceCloud.Instance.User?.UserName)
                .SetSource("this try")
                .Submit();
            }
            int.Parse("asdfasdf");
        }
   private static void App_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
        {
            e.Exception.ToExceptionless()
            .SetUserIdentity(ServiceCloud.Instance.User?.UserId.ToString(), ServiceCloud.Instance.User?.UserName)
            .SetSource("this App_DispatcherUnhandledException")
            .Submit();
        }

I submitted two error logs and set UserIdentity and Source But the UserIdentity and Source received by the server are only useful in the Try block. It does not take effect in global exception events Is this my problem?

Below is a screenshot of the log I received

image

image

image

Logs submitted by App_DispatcherUnhandledException event I don't receive UserIdentity and SetSource So what should I do to make the log submitted by the: App_DispatcherUnhandledException event include UserIdentity and SetSource? grateful!

niemyjski commented 1 year ago

Can you confirm that the App_DispatcherUnhandledException callback has ServiceCloud.Instance.User populated? If it's not, then it will fall back to the authenticated user on the http context / windows account.

Do you have a small sample app I can use to run the above snippets, or could you update our sample apps with this code. I just need an easy way to test this.

q812143836 commented 1 year ago

您能否确认 App_DispatcherUnhandledException 回调已填充 ServiceCloud.Instance.User?如果不是,那么它将回退到 http 上下文/windows 帐户上的经过身份验证的用户。

你有我可以用来运行上述代码片段的小示例应用程序吗,或者你可以用这段代码更新我们的示例应用程序吗?我只需要一种简单的方法来测试它。

image

I just need to comment out this line of code to receive all the extra information

niemyjski commented 1 year ago

You should call Register which automatically registers up to the dispatcher exception handlers. You don't need to call Startup. Also, you can set a global user on the exceptionless client, I'd recommend this for desktop client.

niemyjski commented 1 year ago

@q812143836 does this help? I wouldn't wire up App_DispatcherUnhandledException as we already do that. I would probably add a custom plugin to set the user .SetUserIdentity(ServiceCloud.Instance.User?.UserId.ToString(), ServiceCloud.Instance.User?.UserName)

niemyjski commented 1 year ago

I'm closing this as the two previous comments address this issue specifically. The issue is happening because our unhandled event handlers don't set user information. I'd recommend setting user identity in a plugin in this case. Please let us know if you have any questions.