• Print
  • Share
  • Dark
    Light

Capturing User & Customer Details

  • Updated on 18 Aug 2018
  • 1 minute to read
  • Contributors

When troubleshooting exceptions in your application, it is extremely useful to know the user and customer impacted by the exception.

Retrace's .NET library, StackifyLib, provides a mechanism to report these details whenever an exception occurs.

Within your Global.asax or Startup.cs you want to setup a global event handler.

public override void Init()
{
	base.Init();

	//setup the global call back
	StackifyLib.StackifyError.OnCaptureDetail += StackifyException_OnCaptureDetail;
}

Then, within the callback you can specify the user and customer details.

void StackifyException_OnCaptureDetail(StackifyError ex)
{
	try
	{
		//However you access details about the currently logged in user, you will want to do that here
		if (HttpContext.Current != null)
		{
			var session = FormsAuthSession.FromContext(HttpContext.Current);
			if (session != null)
			{
				//Set the customer and user names however you would like
               //Keep things like GDPR and data privacy in mind if those are a concern for your organization
				ex.CustomerName = session.Client.Value.ToString();
				ex.UserName = session.Username;
			}
		}

	}
	catch (Exception)
	{
		// intentionally ignored
	}
}

Anytime an exception is logged to StackifyLib manually or via our logging appenders (log4net, NLog, Serilog, etc), this global handler will fire.

These details will then show within Retrace's user interface and log viewer.

When selecting a specific exception to view all the details and history of it, you can change the user interface to group by customer or user.

image.png

Within the log viewer and exception module both you can click to view the full JSON document for an exception and look for the customer and user fields.

image.png

Using the log viewer's field explorer you can also select the customer and user fields under Errors to display them in the log viewer. Select the fields and then click Apply Fields.

image.png

You can also click the filter icon next the field to see the number of errors found per customer. You can then select those customers and filter all of your logs down to just the errors for those customers.

image.png