Skip to content

Commit

Permalink
Improved logging in the app to figure out the cause of the error
Browse files Browse the repository at this point in the history
  • Loading branch information
manojmalik20 committed May 2, 2022
1 parent 4ea53d2 commit 1b205f0
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 15 deletions.
9 changes: 4 additions & 5 deletions PresenceProvider/Mattermost/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ private void InitializeStore()
}
} catch (Exception ex)
{
Trace.TraceError(ex.Message);
Trace.TraceError(ex.StackTrace);
Utils.LogException(ex);
}
}

Expand All @@ -109,7 +108,7 @@ private void InitializeWebsocketClientInNewThread()
}
catch (Exception ex)
{
Trace.TraceError("ERROR: " + ex.ToString());
Utils.LogException(ex);
}
}

Expand All @@ -135,7 +134,7 @@ private void InitializeWebsocketClient()
Trace.TraceInformation("Disconnection happened, type: " + info.Type);
if (info.Type == DisconnectionType.Error || info.Type == DisconnectionType.ByServer)
{
throw new Exception("Error in connecting to websocket server.");
Trace.TraceError($"Error in connecting to the websocket server: {info.Type}");
}
});

Expand Down Expand Up @@ -165,7 +164,7 @@ private string GetValueFromConfig(string key)
return configNode[key].GetValue<string>();
} catch (Exception ex)
{
Trace.TraceError(ex.Message);
Utils.LogException(ex);
return string.Empty;
}
}
Expand Down
14 changes: 12 additions & 2 deletions PresenceProvider/Mattermost/Store.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.Collections.Generic;
using System;
using System.Diagnostics;
using System.Collections.Generic;
using UCCollaborationLib;

namespace OutlookPresenceProvider.Mattermost
Expand All @@ -18,7 +20,15 @@ public void Add(string email, string status)

public ContactAvailability GetAvailability(string email)
{
return Constants.StatusAvailabilityMap(_store[email]);
try
{
Trace.TraceInformation($"Returning availability of user: {email} from the store.");
return Constants.StatusAvailabilityMap(_store[email]);
} catch (Exception ex)
{
Utils.LogException(ex);
return ContactAvailability.ucAvailabilityOffline;
}
}

public bool Remove(string email)
Expand Down
6 changes: 2 additions & 4 deletions PresenceProvider/OtherInterfaces/IMClientContact.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,7 @@ public object GetContactInformation(ContactInformationType _contactInformationTy
}
} catch (Exception ex)
{
Trace.TraceError(ex.Message);
Trace.TraceError(ex.StackTrace);
Utils.LogException(ex);
return null;
}
}
Expand Down Expand Up @@ -176,8 +175,7 @@ public void RaiseOnContactInformationChangedEvent(ContactInformationChangedEvent
handler(this, _eventData);
} catch (Exception ex)
{
Trace.TraceError(ex.Message);
Trace.TraceError(ex.StackTrace);
Utils.LogException(ex);
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions PresenceProvider/OtherInterfaces/IMClientContactManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ public AsynchronousOperation Lookup(string _lookupString, object _contactsAndGro
callback.OnLookup(this, null, asyncOperation);
} catch (Exception ex)
{
Trace.TraceError(ex.Message);
Trace.TraceError(ex.StackTrace);
Utils.LogException(ex);
}
return asyncOperation;
}
Expand Down
1 change: 1 addition & 0 deletions PresenceProvider/OutLookPresenceProvider.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@
<Compile Include="OtherInterfaces\IMClientStateChangedEventData.cs" />
<Compile Include="PresenceProvider.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Utils.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\OutOfProcessCOMBase\OutOfProcessCOMBase.csproj">
Expand Down
3 changes: 1 addition & 2 deletions PresenceProvider/PresenceProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ public static void Register(Type t)
}
catch (Exception ex)
{
Trace.TraceError(ex.Message); // Log the error
Trace.TraceError(ex.StackTrace);
Utils.LogException(ex);
throw ex; // Re-throw the exception
}
}
Expand Down
19 changes: 19 additions & 0 deletions PresenceProvider/Utils.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using System.Diagnostics;

namespace OutlookPresenceProvider
{
public class Utils
{
public static void LogException(Exception ex)
{
if (ex == null)
{
return;
}

Trace.TraceError(ex.Message);
Trace.TraceError(ex.StackTrace);
}
}
}

0 comments on commit 1b205f0

Please sign in to comment.