Skip to content

Commit

Permalink
Added logging through a log file
Browse files Browse the repository at this point in the history
  • Loading branch information
manojmalik20 committed Apr 26, 2022
1 parent 0dd9d30 commit 9e3777b
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 28 deletions.
22 changes: 9 additions & 13 deletions CSExeCOMServer/TypeLib.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,38 +10,34 @@ internal static class TypeLib
{
public static void Register(string tlbPath)
{
Trace.WriteLine($"Registering type library:");
Trace.Indent();
Trace.WriteLine(tlbPath);
Trace.Unindent();
Trace.TraceInformation($"Registering type library:");
Trace.TraceInformation(tlbPath);
ComTypes.ITypeLib typeLib;
int hr = OleAut32.LoadTypeLibEx(tlbPath, OleAut32.REGKIND.REGKIND_NONE, out typeLib);
if (hr < 0)
{
Trace.WriteLine($"Registering type library failed: 0x{hr:x}");
Trace.TraceError($"Registering type library failed: 0x{hr:x}");
return;
}
hr = OleAut32.RegisterTypeLibForUser(typeLib, tlbPath, string.Empty);
if (hr < 0)
{
Trace.WriteLine($"Registering type library failed: 0x{hr:x}");
Trace.TraceError($"Registering type library failed: 0x{hr:x}");
return;
}
Trace.WriteLine($"Registering type library succeeded.");
Trace.TraceInformation($"Registering type library succeeded.");
}

public static void Unregister(string tlbPath)
{
Trace.WriteLine($"Unregistering type library:");
Trace.Indent();
Trace.WriteLine(tlbPath);
Trace.Unindent();
Trace.TraceInformation($"Unregistering type library:");
Trace.TraceInformation(tlbPath);

ComTypes.ITypeLib typeLib;
int hr = OleAut32.LoadTypeLibEx(tlbPath, OleAut32.REGKIND.REGKIND_NONE, out typeLib);
if (hr < 0)
{
Trace.WriteLine($"Unregistering type library failed: 0x{hr:x}");
Trace.TraceError($"Unregistering type library failed: 0x{hr:x}");
return;
}

Expand All @@ -55,7 +51,7 @@ public static void Unregister(string tlbPath)
hr = OleAut32.UnRegisterTypeLib(ref attr.guid, attr.wMajorVerNum, attr.wMinorVerNum, attr.lcid, attr.syskind);
if (hr < 0)
{
Trace.WriteLine($"Unregistering type library failed: 0x{hr:x}");
Trace.TraceError($"Unregistering type library failed: 0x{hr:x}");
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions CSExeCOMServer/app.config
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,12 @@
</dependentAssembly>
</assemblyBinding>
</runtime>
<system.diagnostics>
<trace autoflush="true" indentsize="4">
<listeners>
<add name="fileLogger" type="System.Diagnostics.TextWriterTraceListener" initializeData="LogFile.log" traceOutputOptions="DateTime" />
<remove name="Default" />
</listeners>
</trace>
</system.diagnostics>
</configuration>
16 changes: 8 additions & 8 deletions PresenceProvider/Mattermost/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ private void UpdateURLs()
_serverUrl = GetValueFromConfig(Constants.MattermostServerURL);
if (_secret == string.Empty || _serverUrl == string.Empty)
{
Trace.WriteLine("Invalid server url or secret.");
Trace.TraceError("Invalid server url or secret.");
throw new Exception("Invalid server url or secret.");
}
_pluginUrl = new Uri($"{_serverUrl}/plugins/{Constants.PluginId}/api/v1/");
Expand Down Expand Up @@ -90,7 +90,7 @@ private void InitializeStore()
}
} catch (Exception ex)
{
Trace.WriteLine(ex.StackTrace);
Trace.TraceError(ex.StackTrace);
}
}

Expand All @@ -104,11 +104,11 @@ private void InitializeWebsocketClientInNewThread()

// Wait for the websocket client "_wsClient" to get initialized by the other thread running parallely
while (_wsClient == null) ;
Trace.WriteLine("Websocket client connected.");
Trace.TraceInformation("Websocket client connected.");
}
catch (Exception ex)
{
Trace.WriteLine("ERROR: " + ex.ToString());
Trace.TraceError("ERROR: " + ex.ToString());
}
}

Expand All @@ -126,12 +126,12 @@ private void InitializeWebsocketClient()
client.ReconnectTimeout = TimeSpan.FromSeconds(wsTimeout);
client.ReconnectionHappened.Subscribe(info =>
{
Trace.WriteLine("Reconnection happened, type: " + info.Type);
Trace.TraceInformation("Reconnection happened, type: " + info.Type);
});

client.DisconnectionHappened.Subscribe(info =>
{
Trace.WriteLine("Disconnection happened, type: " + info.Type);
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.");
Expand All @@ -142,7 +142,7 @@ private void InitializeWebsocketClient()
_wsClient = client;
mre.WaitOne();

Trace.WriteLine("Websocket client closed.");
Trace.TraceInformation("Websocket client closed.");
}

private string GetValueFromConfig(string key)
Expand All @@ -164,7 +164,7 @@ private string GetValueFromConfig(string key)
return configNode[key].GetValue<string>();
} catch (Exception ex)
{
Trace.WriteLine(ex.Message);
Trace.TraceError(ex.Message);
return string.Empty;
}
}
Expand Down
2 changes: 1 addition & 1 deletion PresenceProvider/OtherInterfaces/IMClientAsyncOperation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public IMClientAsyncOperation()

public void CancelOperation()
{
Trace.WriteLine("Operation cancelled");
Trace.TraceInformation("Operation cancelled");
}

private dynamic _asyncState;
Expand Down
4 changes: 2 additions & 2 deletions PresenceProvider/OtherInterfaces/IMClientContact.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public object GetContactInformation(ContactInformationType _contactInformationTy
}
} catch (Exception ex)
{
Trace.WriteLine(ex.StackTrace);
Trace.TraceError(ex.StackTrace);
return null;
}
}
Expand Down Expand Up @@ -175,7 +175,7 @@ public void RaiseOnContactInformationChangedEvent(ContactInformationChangedEvent
handler(this, _eventData);
} catch (Exception ex)
{
Trace.WriteLine(ex.StackTrace);
Trace.TraceError(ex.StackTrace);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion PresenceProvider/OtherInterfaces/IMClientContactManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public AsynchronousOperation Lookup(string _lookupString, object _contactsAndGro
callback.OnLookup(this, null, asyncOperation);
} catch (Exception ex)
{
Trace.WriteLine(ex.StackTrace);
Trace.TraceError(ex.StackTrace);
}
return asyncOperation;
}
Expand Down
5 changes: 2 additions & 3 deletions PresenceProvider/PresenceProvider.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

#region Using directives
#region Using directives
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
Expand Down Expand Up @@ -35,7 +34,7 @@ public static void Register(Type t)
}
catch (Exception ex)
{
Trace.WriteLine(ex.StackTrace); // Log the error
Trace.TraceError(ex.StackTrace); // Log the error
throw ex; // Re-throw the exception
}
}
Expand Down

0 comments on commit 9e3777b

Please sign in to comment.