From 1c1235509f5985fc6a26356ca4ec84e45e782f78 Mon Sep 17 00:00:00 2001 From: cruikshj Date: Sun, 20 Nov 2016 13:37:34 -0600 Subject: [PATCH] feat: log failures to event log --- .../CustomActions.cs | 50 ++++++++++++++++--- SMLogging.Setup/Product.wxs | 16 +++++- SMLogging.Setup/SMLogging.Setup.wixproj | 4 ++ 3 files changed, 62 insertions(+), 8 deletions(-) diff --git a/SMLogging.Setup.CustomActions/CustomActions.cs b/SMLogging.Setup.CustomActions/CustomActions.cs index 272b016..77af50f 100644 --- a/SMLogging.Setup.CustomActions/CustomActions.cs +++ b/SMLogging.Setup.CustomActions/CustomActions.cs @@ -83,11 +83,11 @@ private static void RegisterRequestLogging(string path, Session session) var sourcesElement = GetOrAddElement(document.Root, "system.diagnostics", "sources"); if (sourcesElement.XPathSelectElement($"source[@name='{RequestLoggingSourceName}']") == null) { - sourcesElement.Add(new XElement("source", - new XAttribute("name", RequestLoggingSourceName), + sourcesElement.Add(new XElement("source", + new XAttribute("name", RequestLoggingSourceName), new XAttribute("switchValue", RequestLoggingSourceSwitchValue), - new XElement("listeners", - new XElement("remove", + new XElement("listeners", + new XElement("remove", new XAttribute("name", "Default")), new XElement("add", new XAttribute("name", FileTraceListenerName), @@ -96,7 +96,21 @@ private static void RegisterRequestLogging(string path, Session session) new XAttribute("rollingMode", data["RequestLoggingRollingMode"]), new XAttribute("rollingInterval", data["RequestLoggingRollingInterval"]), new XAttribute("maximumFileSize", data["RequestLoggingMaximumFileSize"]), - new XAttribute("maximumFileIndex", data["RequestLoggingMaximumFileIndex"]))))); + new XAttribute("maximumFileIndex", data["RequestLoggingMaximumFileIndex"]), + new XAttribute("failTraceSource", RequestLoggingFailSourceName))))); + } + if (sourcesElement.XPathSelectElement($"source[@name='{RequestLoggingFailSourceName}']") == null) + { + sourcesElement.Add(new XElement("source", + new XAttribute("name", RequestLoggingFailSourceName), + new XAttribute("switchValue", RequestLoggingFailSourceSwitchValue), + new XElement("listeners", + new XElement("remove", + new XAttribute("name", "Default")), + new XElement("add", + new XAttribute("name", EventLogListenerName), + new XAttribute("type", EventLogTraceListenerType), + new XAttribute("initializeData", EventLogSourceName))))); } document.Save(path); @@ -118,6 +132,7 @@ private static void UnregisterRequestLogging(string path, Session session) document.Root?.XPathSelectElement($"system.serviceModel/commonBehaviors/serviceBehaviors/{RequestLoggingBehaviorName}")?.Remove(); document.Root?.XPathSelectElement($"system.serviceModel/commonBehaviors/endpointBehaviors/{RequestLoggingBehaviorName}")?.Remove(); document.Root?.XPathSelectElement($"system.diagnostics/sources/source[@name='{RequestLoggingSourceName}']")?.Remove(); + document.Root?.XPathSelectElement($"system.diagnostics/sources/source[@name='{RequestLoggingFailSourceName}']")?.Remove(); document.Save(path); } @@ -200,7 +215,22 @@ private static void RegisterErrorLogging(string path, Session session) new XAttribute("rollingMode", data["ErrorLoggingRollingMode"]), new XAttribute("rollingInterval", data["ErrorLoggingRollingInterval"]), new XAttribute("maximumFileSize", data["ErrorLoggingMaximumFileSize"]), - new XAttribute("maximumFileIndex", data["ErrorLoggingMaximumFileIndex"]))))); + new XAttribute("maximumFileIndex", data["ErrorLoggingMaximumFileIndex"]), + new XAttribute("failTraceSource", ErrorLoggingFailSourceName))))); + } + + if (sourcesElement.XPathSelectElement($"source[@name='{ErrorLoggingFailSourceName}']") == null) + { + sourcesElement.Add(new XElement("source", + new XAttribute("name", ErrorLoggingFailSourceName), + new XAttribute("switchValue", ErrorLoggingFailSourceSwitchValue), + new XElement("listeners", + new XElement("remove", + new XAttribute("name", "Default")), + new XElement("add", + new XAttribute("name", EventLogListenerName), + new XAttribute("type", EventLogTraceListenerType), + new XAttribute("initializeData", EventLogSourceName))))); } document.Save(path); @@ -221,6 +251,7 @@ private static void UnregisterErrorLogging(string path, Session session) document.Root?.XPathSelectElement($"system.serviceModel/extensions/behaviorExtensions/add[@name='{ErrorLoggingBehaviorName}']")?.Remove(); document.Root?.XPathSelectElement($"system.serviceModel/commonBehaviors/serviceBehaviors/{ErrorLoggingBehaviorName}")?.Remove(); document.Root?.XPathSelectElement($"system.diagnostics/sources/source[@name='{ErrorLoggingSourceName}']")?.Remove(); + document.Root?.XPathSelectElement($"system.diagnostics/sources/source[@name='{ErrorLoggingFailSourceName}']")?.Remove(); document.Save(path); } @@ -313,6 +344,13 @@ private static void SetupDirectory(string path) private const string ErrorLoggingSourceSwitchValue = "Error"; private const string FileTraceListenerName = "File"; private const string BackgroundFileTraceListenerTypeFormat = "SMLogging.BackgroundFileTraceListener, SMLogging, Version={0}.0, Culture=neutral, PublicKeyToken=ddc81ec55fc35caf"; + private const string RequestLoggingFailSourceName = "System.ServiceModel.RequestLogging.Fail"; + private const string RequestLoggingFailSourceSwitchValue = "Error"; + private const string ErrorLoggingFailSourceName = "System.ServiceModel.ErrorLogging.Fail"; + private const string ErrorLoggingFailSourceSwitchValue = "Error"; + private const string EventLogListenerName = "EventLog"; + private const string EventLogTraceListenerType = "System.Diagnostics.EventLogTraceListener"; + private const string EventLogSourceName = "SMLogging"; #endregion } diff --git a/SMLogging.Setup/Product.wxs b/SMLogging.Setup/Product.wxs index 022fe21..0217097 100644 --- a/SMLogging.Setup/Product.wxs +++ b/SMLogging.Setup/Product.wxs @@ -19,11 +19,16 @@ + + - + + + + @@ -66,7 +71,7 @@ - + @@ -86,5 +91,12 @@ + + + + + + + \ No newline at end of file diff --git a/SMLogging.Setup/SMLogging.Setup.wixproj b/SMLogging.Setup/SMLogging.Setup.wixproj index a913b06..adb8862 100644 --- a/SMLogging.Setup/SMLogging.Setup.wixproj +++ b/SMLogging.Setup/SMLogging.Setup.wixproj @@ -26,6 +26,10 @@ + + $(WixExtDir)\WixNetFxExtension.dll + WixNetFxExtension + $(WixExtDir)\WixUtilExtension.dll WixUtilExtension