Permalink
Browse files

System.Diagnostics.Trace bridge added as a C1 log listener - will rep…

…licate log data onto standard Trace. See Composite.config file change in this commit for how to enable.
  • Loading branch information...
mawtex committed Nov 30, 2018
1 parent 53ad132 commit ebefdaac4d963d8ed0be849ab9dbbb933d644e2e
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -261,6 +261,7 @@
<Compile Include="Plugins\Elements\UrlToEntityToken\WebsiteFileUrlToEntityTokenMapper.cs" />
<Compile Include="Plugins\Elements\UrlToEntityToken\MediaUrlToEntityTokenMapper.cs" />
<Compile Include="Plugins\Functions\WidgetFunctionProviders\StandardWidgetFunctionProvider\String\HierarchicalSelectorWidgetFunction.cs" />
<Compile Include="Plugins\Logging\LogTraceListeners\SystemDiagnosticsTrace\SystemDiagnosticsTraceBridge.cs" />
<Compile Include="Properties\GitCommitInfo.cs" />
<Compile Include="Search\Crawling\DataFieldProcessors\DateTimeDataFieldProcessor.cs" />
<Compile Include="Search\Crawling\DataFieldProcessors\FileNameDataFieldProcessor.cs" />
@@ -2686,8 +2687,8 @@
</PropertyGroup>
<Exec Condition="Exists('$(SolutionDir)\.git')" Command="git -C $(ProjectDir) rev-parse --abbrev-ref HEAD&gt; &quot;$(GitBranchFile)&quot;" />
<Exec Condition="Exists('$(SolutionDir)\.git')" Command="git -C $(ProjectDir) rev-parse HEAD&gt; &quot;$(GitCommitHashFile)&quot;" />
<Exec Condition="!Exists('$(SolutionDir)\.git')" Command="@echo unknown branch > &quot;$(GitBranchFile)&quot;" />
<Exec Condition="!Exists('$(SolutionDir)\.git')" Command="@echo unknown commit > &quot;$(GitCommitHashFile)&quot;" />
<Exec Condition="!Exists('$(SolutionDir)\.git')" Command="@echo unknown branch &gt; &quot;$(GitBranchFile)&quot;" />
<Exec Condition="!Exists('$(SolutionDir)\.git')" Command="@echo unknown commit &gt; &quot;$(GitCommitHashFile)&quot;" />
<PropertyGroup>
<GitBranch>$([System.IO.File]::ReadAllText("$(GitBranchFile)").Trim())</GitBranch>
<GitCommitHash>$([System.IO.File]::ReadAllText("$(GitCommitHashFile)").Trim())</GitCommitHash>
@@ -0,0 +1,63 @@
using System;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Logging.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners;

namespace Composite.Plugins.Logging.LogTraceListeners.SystemDiagnosticsTrace
{
[ConfigurationElementType(typeof(CustomTraceListenerData))]
internal sealed class SystemDiagnosticsTraceBridge : CustomTraceListener
{
public SystemDiagnosticsTraceBridge()
{
}

public SystemDiagnosticsTraceBridge(string initializeData)
{
}

public override void TraceData(System.Diagnostics.TraceEventCache eventCache, string source, System.Diagnostics.TraceEventType eventType, int id, object data)
{
var logEntry = (Microsoft.Practices.EnterpriseLibrary.Logging.LogEntry)data;

string title = logEntry.Title;
title = title.Substring(title.IndexOf(')') + 2); // Removing ({AppDomainId} - {ThreadId}}) prefix.
if (title.StartsWith("RGB("))

This comment has been minimized.

@burningice2866

burningice2866 Dec 2, 2018

Contributor

Would be nice to have something like a C1CMSCustomTraceListener class with this logic as a protected helper method since i also find myself having to implement this logic over and over again

{
string displayOptions = title.Substring(0, title.IndexOf(')') + 1);
title = title.Substring(displayOptions.Length);
}

string message = String.Format("[{0}] {1}", title, logEntry.Message);

switch (logEntry.Severity)
{
case System.Diagnostics.TraceEventType.Critical:
case System.Diagnostics.TraceEventType.Error:
System.Diagnostics.Trace.TraceError(message);
break;
case System.Diagnostics.TraceEventType.Warning:
System.Diagnostics.Trace.TraceWarning(message);
break;
case System.Diagnostics.TraceEventType.Information:
System.Diagnostics.Trace.TraceInformation(message);
break;
default:
System.Diagnostics.Trace.WriteLine(message);
break;
}

System.Diagnostics.Trace.Flush();
}

public override void Write(string message)
{
System.Diagnostics.Trace.Write(message);
}

public override void WriteLine(string message)
{
System.Diagnostics.Trace.WriteLine(message);
}
}
}
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="Composite.Data.Plugins.DataProviderConfiguration" type="Composite.Data.Plugins.DataProvider.Runtime.DataProviderSettings, Composite" />
@@ -478,8 +478,9 @@
<loggingConfiguration name="Logging Application Block" tracingEnabled="true" defaultCategory="General" logWarningsWhenNoCategoriesMatch="true">
<listeners>
<add source="Freja" formatter="Text Formatter" log="Application" machineName="" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.0.0.0" traceOutputOptions="None" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.0.0.0" name="Formatted EventLog TraceListener" />
<add listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.CustomTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.0.0.0" traceOutputOptions="None" type="Composite.Plugins.Logging.LogTraceListeners.FileLogTraceListener.FileLogTraceListener, Composite" name="FileLogTraceListener" initializeData="App_Data\Composite\LogFiles,false" formatter="Text Formatter" />
</listeners>
<add name="FileLogTraceListener" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.CustomTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.0.0.0" traceOutputOptions="None" type="Composite.Plugins.Logging.LogTraceListeners.FileLogTraceListener.FileLogTraceListener, Composite" initializeData="App_Data\Composite\LogFiles,false" formatter="Text Formatter" />
<add name="SystemDiagnosticsTraceBridge" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.CustomTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.0.0.0" traceOutputOptions="None" type="Composite.Plugins.Logging.LogTraceListeners.SystemDiagnosticsTrace.SystemDiagnosticsTraceBridge, Composite" initializeData="" formatter="Text Formatter" />
</listeners>
<formatters>
<add template="Timestamp: {timestamp}&#xD;&#xA;Message: {message}&#xD;&#xA;Category: {category}&#xD;&#xA;Priority: {priority}&#xD;&#xA;EventId: {eventid}&#xD;&#xA;Severity: {severity}&#xD;&#xA;Title: {title}&#xD;&#xA;Machine: {machine}&#xD;&#xA;Application Domain: {appDomain}&#xD;&#xA;Process Id: {processId}&#xD;&#xA;Process Name: {processName}&#xD;&#xA;Win32 Thread Id: {win32ThreadId}&#xD;&#xA;Thread Name: {threadName}&#xD;&#xA;Extended Properties: {dictionary({key} - {value}&#xD;&#xA;)}" type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.0.0.0" name="Text Formatter" />
</formatters>
@@ -490,7 +491,8 @@
<allEvents switchValue="All" name="All Events">
<listeners>
<add name="FileLogTraceListener" />
</listeners>
<add name="SystemDiagnosticsTraceBridge" />
</listeners>
</allEvents>
<notProcessed switchValue="All" name="Unprocessed Category" />
<errors switchValue="All" name="Logging Errors &amp; Warnings" />
@@ -472,8 +472,9 @@
<loggingConfiguration name="Logging Application Block" tracingEnabled="true" defaultCategory="General" logWarningsWhenNoCategoriesMatch="true">
<listeners>
<add source="Freja" formatter="Text Formatter" log="Application" machineName="" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.0.0.0" traceOutputOptions="None" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.0.0.0" name="Formatted EventLog TraceListener"/>
<add listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.CustomTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.0.0.0" traceOutputOptions="None" type="Composite.Plugins.Logging.LogTraceListeners.FileLogTraceListener.FileLogTraceListener, Composite" name="FileLogTraceListener" initializeData="App_Data\Composite\LogFiles,false" formatter="Text Formatter" />
</listeners>
<add name="FileLogTraceListener" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.CustomTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.0.0.0" traceOutputOptions="None" type="Composite.Plugins.Logging.LogTraceListeners.FileLogTraceListener.FileLogTraceListener, Composite" initializeData="App_Data\Composite\LogFiles,false" formatter="Text Formatter" />
<add name="SystemDiagnosticsTraceBridge" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.CustomTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.0.0.0" traceOutputOptions="None" type="Composite.Plugins.Logging.LogTraceListeners.SystemDiagnosticsTrace.SystemDiagnosticsTraceBridge, Composite" initializeData="" formatter="Text Formatter" />
</listeners>
<formatters>
<add template="Timestamp: {timestamp}&#xD;&#xA;Message: {message}&#xD;&#xA;Category: {category}&#xD;&#xA;Priority: {priority}&#xD;&#xA;EventId: {eventid}&#xD;&#xA;Severity: {severity}&#xD;&#xA;Title: {title}&#xD;&#xA;Machine: {machine}&#xD;&#xA;Application Domain: {appDomain}&#xD;&#xA;Process Id: {processId}&#xD;&#xA;Process Name: {processName}&#xD;&#xA;Win32 Thread Id: {win32ThreadId}&#xD;&#xA;Thread Name: {threadName}&#xD;&#xA;Extended Properties: {dictionary({key} - {value}&#xD;&#xA;)}" type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.0.0.0"
name="Text Formatter"/>
@@ -485,7 +486,8 @@
<allEvents switchValue="Information" name="All Events">
<listeners>
<add name="FileLogTraceListener" />
</listeners>
<add name="SystemDiagnosticsTraceBridge" />
</listeners>
</allEvents>
<notProcessed switchValue="All" name="Unprocessed Category"/>
<errors switchValue="All" name="Logging Errors &amp; Warnings"/>
@@ -1,4 +1,4 @@
Changes since released 1.0.3070.24011 (Nightly build 20080528.5)
Changes since released 1.0.3070.24011 (Nightly build 20080528.5)
- <ToolbarButton /> added to std. Form UI Markup.
- Composite.Core.Application.Plugins.ApplicationOnlineHandlerConfiguration added
- <InfoBox /> added to std. Form UI Markup.
@@ -166,4 +166,8 @@ Changes in 6.0 or later
<ComponentProviders>
<add name="FileBasedComponentProvider" type="Composite.Plugins.Components.FileBasedComponentProvider, Composite" directory="~/App_Data/Components" fileSearchPattern="*.xml" topDirectoryOnly="false"/>
</ComponentProviders>
</Composite.Plugins.Components.ComponentProviderConfiguration>
</Composite.Plugins.Components.ComponentProviderConfiguration>

Changes in 6.6 or later:
-Added <add name="SystemDiagnosticsTraceBridge" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.CustomTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.0.0.0" traceOutputOptions="None" type="Composite.Plugins.Logging.LogTraceListeners.SystemDiagnosticsTrace.SystemDiagnosticsTraceBridge, Composite" initializeData="" formatter="Text Formatter" /> to loggingConfiguration/listeners
-Added <add name="SystemDiagnosticsTraceBridge" /> to loggingConfiguration/specialSources/allEvents/listeners

0 comments on commit ebefdaa

Please sign in to comment.