Skip to content
This repository has been archived by the owner on Feb 20, 2021. It is now read-only.

Added exception details #2

Merged
merged 3 commits into from
May 3, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 24 additions & 5 deletions source/Src/SemanticLogging.Etw.WindowsService/ParameterOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,7 @@ public void ConsoleMode()
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
Console.WriteLine();
Console.WriteLine(Resources.StopServiceMessage);
Console.ReadLine();
this.ExitCode = ApplicationExitCode.RuntimeError;
DisplayExceptionOnConsole(e);
}
}

Expand All @@ -185,6 +181,29 @@ private static ServiceController GetController()
return ServiceController.GetServices().FirstOrDefault(s => s.ServiceName.Equals(Constants.ServiceName, StringComparison.OrdinalIgnoreCase));
}

private void DisplayExceptionOnConsole(Exception e)
{
var rtle = e as ReflectionTypeLoadException;
if (rtle != null)
{
DisplayLoaderExceptionsOnConsole(rtle);
}

Console.WriteLine(e.ToString());
Console.WriteLine();
Console.WriteLine(Resources.StopServiceMessage);
Console.ReadLine();
this.ExitCode = ApplicationExitCode.RuntimeError;
}

private void DisplayLoaderExceptionsOnConsole(ReflectionTypeLoadException e)
{
foreach (var loaderException in e.LoaderExceptions)
{
Console.WriteLine(loaderException.ToString());
}
}

private bool IsAuthorized()
{
var user = WindowsIdentity.GetCurrent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using System.Threading.Tasks;
using Microsoft.Practices.EnterpriseLibrary.SemanticLogging.Etw.Configuration;
using Microsoft.Practices.EnterpriseLibrary.SemanticLogging.Etw.Service.Properties;
using System.Reflection;

namespace Microsoft.Practices.EnterpriseLibrary.SemanticLogging.Etw.Service
{
Expand Down Expand Up @@ -73,7 +74,7 @@ protected override void OnStart(string[] args)
// log and rethrow to notify SCM
if (!this.consoleMode)
{
this.EventLog.WriteEntry(e.ToString(), EventLogEntryType.Error);
LogException(e);
}

throw;
Expand Down Expand Up @@ -333,5 +334,24 @@ private void NotifyError(Exception error)
this.EventLog.WriteEntry(error.ToString(), EventLogEntryType.Error);
}
}

private void LogException(Exception e)
{
var rtle = e as ReflectionTypeLoadException;
if (rtle != null)
{
LogLoaderExceptions(rtle);
}

this.EventLog.WriteEntry(e.ToString(), EventLogEntryType.Error);
}

private void LogLoaderExceptions(ReflectionTypeLoadException e)
{
foreach (var loaderException in e.LoaderExceptions)
{
this.EventLog.WriteEntry(loaderException.ToString(), EventLogEntryType.Error);
}
}
}
}