Skip to content
This repository has been archived by the owner on May 11, 2024. It is now read-only.

Commit

Permalink
feat: log failures to event log
Browse files Browse the repository at this point in the history
  • Loading branch information
cruikshj committed Nov 20, 2016
1 parent da9b662 commit 1c12355
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 8 deletions.
50 changes: 44 additions & 6 deletions SMLogging.Setup.CustomActions/CustomActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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);
Expand All @@ -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);
}
Expand Down Expand Up @@ -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);
Expand All @@ -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);
}
Expand Down Expand Up @@ -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
}
Expand Down
16 changes: 14 additions & 2 deletions SMLogging.Setup/Product.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,16 @@
<Property Id="ERRORLOGGINGMAXIMUMFILEINDEX" Value="1" Secure="yes"/>
<Property Id="CREATEBUFFEREDMESSAGECOPY" Value="false" Secure="yes"/>
<Property Id="IGNOREDISPATCHREPLYMESSAGE" Value="false" Secure="yes"/>

<PropertyRef Id="NETFRAMEWORK40FULLINSTALLROOTDIR"/>

<Feature Id="AssemblyFeature" Title="Install service model logging assembly" Level="1" Absent="disallow">
<ComponentGroupRef Id="AssemblyComponents"/>
</Feature>
<Feature Id="RequestLoggingMachineConfigFeature" Title="Register request logging in machine.config" Level="1"/>
<Feature Id="EventSourceFeature" Title="Install SMLogging event source for logging failures" Level="1" >
<ComponentGroupRef Id="EventSourceComponents"/>
</Feature>
<Feature Id="RequestLoggingMachineConfigFeature" Title="Register request logging in machine.config" Level="1" />
<Feature Id="ErrorLoggingMachineConfigFeature" Title="Register error logging in machine.config" Level="1"/>
<Feature Id="EnableETETracingMachineConfigFeature" Title="Enable end to end tracing in machine.config" Level="1"/>

Expand Down Expand Up @@ -66,7 +71,7 @@
<Fragment>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="INSTALLFOLDER" Name="Service Model Logging">
<Directory Id="INSTALLFOLDER" Name="Service Model Logging" >
<Directory Id="NET40FOLDER" Name="net40"/>
<Directory Id="NET35FOLDER" Name="net35"/>
</Directory>
Expand All @@ -86,5 +91,12 @@
<File Id="System.Threading.dll_net35_gac" Name="System.Threading.dll" Source="$(var.SMLogging-net35.TargetDir)System.Threading.dll" KeyPath="yes" Vital="yes" Checksum="yes" Assembly=".net" AssemblyManifest="System.Threading.dll_net35_gac"/>
</Component>
</ComponentGroup>

<ComponentGroup Id="EventSourceComponents" >
<Component Id="EventSource" Guid="F1B110D3-6A72-4E87-9CFA-C37A0FF08E26" Directory="INSTALLFOLDER" Permanent="no">
<!-- This assumes .NET 4x is installed. May need to conitionally look for other versions of .NET to get this path. -->
<util:EventSource Log="Application" Name="SMLogging" EventMessageFile="[NETFRAMEWORK40FULLINSTALLROOTDIR]EventLogMessages.dll" KeyPath="yes" />
</Component>
</ComponentGroup>
</Fragment>
</Wix>
4 changes: 4 additions & 0 deletions SMLogging.Setup/SMLogging.Setup.wixproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
<Compile Include="Product.wxs" />
</ItemGroup>
<ItemGroup>
<WixExtension Include="WixNetFxExtension">
<HintPath>$(WixExtDir)\WixNetFxExtension.dll</HintPath>
<Name>WixNetFxExtension</Name>
</WixExtension>
<WixExtension Include="WixUtilExtension">
<HintPath>$(WixExtDir)\WixUtilExtension.dll</HintPath>
<Name>WixUtilExtension</Name>
Expand Down

0 comments on commit 1c12355

Please sign in to comment.