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

net

(arturomonge) #1

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


(antonk) #2

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;
		}
	}

(RemObjects) #4

Thanks, logged as bugs://82080


(arturomonge) #5

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


(antonk) #6

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


(arturomonge) #7

Awesome, thanks!


(RemObjects) #8

bugs://82080 got closed with status fixed.