How to log all exceptions sent to the client in a .NET server

Hi,

I have the following code in a Delphi server:

procedure TLoggedDataAbstractService.DataAbstractServiceDeactivate(const aClientID: TGUID; aSession: TROSession);
var
  vException: TObject;
begin
  inherited;
  vException := ExceptObject;
  if (vException is Exception) and not(vException is EFpNonCriticalException) then
  begin
    // Log exception...
    ServiceLogger.SendException(vException as Exception);
  end;
end;

How can I log all the exceptions sent back to the client, in a .NET server?

Thanks,
Arturo

I’m afraid there is no way to implement similar code in a .NET server. You can only override existing methods of the DataAbstractService like GetData and UpdateData with a code like

	public override int ExecuteCommandEx(string commandName, DataParameter[] inputParameters, out DataParameter[] outputParameters)
	{
		try
		{
			return base.ExecuteCommandEx(commandName, inputParameters, out outputParameters);
		}
		catch (Exception e)
		{
			// Log exception and rethrow it
			throw;
		}
	}

	public override Binary UpdateData(Binary serializedDelta)
	{
		try
		{
			return base.UpdateData(serializedDelta);
		}
		catch (Exception e)
		{
			// Log exception and rethrow it
			throw;
		}
	}

	public override Binary GetData(string[] tableNames, TableRequestInfo[] requestInfo)
	{
		try
		{
			return base.GetData(tableNames, requestInfo);
		}
		catch (Exception e)
		{
			// Log exception and rethrow it
			throw;
		}
	}

Thanks, logged as bugs://82080

Ok, thanks. This means I have to surround every single call to every single method in the server, with logging code for exceptions. Not a problem, but not the cleanest solution either, :slight_smile:. Hopefully you can create an event (possibly where you catch and serialize the exception to send it back to the client), where we can do the logging of the exception object (which I believe issue #82080 is for, :+1: ).

Thank you!

-Arturo

Yes, you are right. The issue #82080 is for adding an event that will be raised when an unhandled exception was raised during the service method execution. This event will provide a centralized place where all such exceptions can be logged.

Unfortunately this change won’t be in the upcoming RTM, but for sure it will be present in one of the first post-release Beta builds

Awesome, thanks!

1 Like

bugs://82080 got closed with status fixed.

Sorry to resurrect this thread.

Which build added this event, is this DA 10 only, i’m having some troubles finding it in our current version:

SDK: 9.7.115.1441

In general we recommend sing the latest stalk builds of RO/DA, as they include all fixes and improvements, including security fixes.

1 Like

Hello Marc,

Agreed for sure! We have a lot of stuff using RO/DA so it’s quite a lot to update/test when we install the latest version, but I had urgent need for this event :wink:

1 Like

Hello

Unfortunately this event is not present in the 9.7.115.1441, it is only present in the DA10 family of builds.

1 Like

Thanks Anton, no problem, we’ll upgrade asap.