Skip to content

Commit

Permalink
Updated library to support ReflectInsight v5.7.0
Browse files Browse the repository at this point in the history
  • Loading branch information
calloncampbell committed May 15, 2017
1 parent f1b54ce commit fc9fb32
Show file tree
Hide file tree
Showing 8 changed files with 125 additions and 51 deletions.
4 changes: 2 additions & 2 deletions Build.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
param(
[String] $majorMinor = "5.6", # 5.6
[String] $patch = "2", # $env:APPVEYOR_BUILD_VERSION
[String] $majorMinor = "5.7", # 5.7
[String] $patch = "0", # $env:APPVEYOR_BUILD_VERSION
[String] $customLogger = "", # C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll
[Switch] $notouch,
[String] $project = "ReflectSoftware.Insight.Extensions.Log4Net"
Expand Down
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## Change Log ##

#### Version 5.7.0 ####
* Updated to ReflectInsight v5.7.0.0

#### Version 5.6.2 ####
* Updated to support latest log4net v2.0.8

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

We've added support for the Log4net appender. This allows you to leverage your current investment in log4net, but leverage the power and flexibility that comes with the ReflectInsight viewer. You can view your log4net messages in realtime, in a rich viewer that allows you to filter out and search for what really matters to you.

The log4net extension supports Log4net v1.2.11.0. However if you need to support an older version, then you will need to download the ReflectInsight Logging Extensions Library from GitHub. You can then reference and rebuild the extension against a specific release of the log4net dll.
The log4net extension supports Log4net v2.0.8. However if you need to support an older version, then you will need to download the ReflectInsight Logging Extensions Library from GitHub. You can then reference and rebuild the extension against a specific release of the log4net dll.

## Benefits of ReflectInsight Extensions ##

Expand Down
6 changes: 3 additions & 3 deletions assets/VersionInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyVersion("5.6.2.1704")]
[assembly: AssemblyFileVersion("5.6.2.1704")]
[assembly: AssemblyInformationalVersion("5.6.2")]
[assembly: AssemblyVersion("5.7.0.1705")]
[assembly: AssemblyFileVersion("5.7.0.1705")]
[assembly: AssemblyInformationalVersion("5.7.0")]
150 changes: 112 additions & 38 deletions src/Log4netAppender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,16 @@

namespace ReflectSoftware.Insight.Extensions.Log4net
{
///------------------------------------------------------------------------
/// <summary> Redirect all log4net messages to ReflectInsight. </summary>
/// <seealso cref="T:log4net.Appender.AppenderSkeleton"/>
///------------------------------------------------------------------------
/// <summary>
/// Redirect all log4net messages to ReflectInsight.
/// </summary>
/// <seealso cref="log4net.Appender.AppenderSkeleton" />
/// <seealso cref="T:log4net.Appender.AppenderSkeleton" />
public class LogAppender : AppenderSkeleton
{
class ActiveStates
{
public ReflectInsight RI { get; set; }
public IReflectInsight RI { get; set; }
public Boolean DisplayLevel { get; set; }
public Boolean DisplayLocation { get; set; }
}
Expand All @@ -40,61 +41,90 @@ class ActiveStates
protected String DisplayLevel { get; set; }
protected String DisplayLocation { get; set; }

///--------------------------------------------------------------------

/// <summary>
/// Initializes the <see cref="LogAppender"/> class.
/// </summary>
/// <remarks>
/// Empty default constructor
/// </remarks>
static LogAppender()
{
FLine = String.Format("{0,40}", String.Empty).Replace(" ", "-");
FSendInternalErrorMethodInfo = typeof(ReflectInsight).GetMethod("SendInternalError", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.InvokeMethod);
}
///--------------------------------------------------------------------
/// <summary> Initializes a new instance of the <see cref="LogAppender" /> class. </summary>
/// <remarks> Empty default constructor. </remarks>
///--------------------------------------------------------------------

/// <summary>
/// Initializes a new instance of the <see cref="LogAppender" /> class.
/// </summary>
/// <remarks>
/// Empty default constructor.
/// </remarks>
/// --------------------------------------------------------------------
/// --------------------------------------------------------------------
public LogAppender()
{
InstanceName = String.Empty;
DisplayLevel = String.Empty;
DisplayLocation = String.Empty;
CurrentActiveStates = new ActiveStates();

RIEventManager.OnServiceConfigChange += DoOnConfigChange;
RIEventManager.OnServiceConfigChange += DoOnConfigChange;
}
///--------------------------------------------------------------------

/// <summary>
/// Raises the Close event.
/// </summary>
/// <remarks>
/// <para>
/// Releases any resources allocated within the appender such as file handles,
/// network connections, etc.
/// </para>
/// <para>
/// It is a programming error to append to a closed appender.
/// </para>
/// </remarks>
protected override void OnClose()
{
RIEventManager.OnServiceConfigChange -= DoOnConfigChange;
base.OnClose();
}
///--------------------------------------------------------------------

/// <summary>
/// Does the on configuration change.
/// </summary>
private void DoOnConfigChange()
{
OnConfigChange();
}
///--------------------------------------------------------------------
/// <summary> Activates the options. </summary>
///
/// <summary>
/// Activates the options.
/// </summary>
/// <remarks>
/// <para>
/// This is part of the <see cref="T:log4net.Core.IOptionHandler" /> delayed object activation
/// scheme. The <see cref="M:log4net.Appender.AppenderSkeleton.ActivateOptions" /> method must
/// be called on this object after the configuration properties have been set. Until
/// <see cref="M:log4net.Appender.AppenderSkeleton.ActivateOptions" /> is called this object
/// is in an undefined state and must not be used.
/// </para>
/// This is part of the <see cref="T:log4net.Core.IOptionHandler" /> delayed object activation
/// scheme. The <see cref="M:log4net.Appender.AppenderSkeleton.ActivateOptions" /> method must
/// be called on this object after the configuration properties have been set. Until
/// <see cref="M:log4net.Appender.AppenderSkeleton.ActivateOptions" /> is called this object
/// is in an undefined state and must not be used.
/// </para>
/// <para>
/// If any of the configuration properties are modified then
/// <see cref="M:log4net.Appender.AppenderSkeleton.ActivateOptions" /> must be called again.
/// </para>
/// If any of the configuration properties are modified then
/// <see cref="M:log4net.Appender.AppenderSkeleton.ActivateOptions" /> must be called again.
/// </para>
/// </remarks>
///
/// <seealso cref="M:log4net.Appender.AppenderSkeleton.ActivateOptions()"/>
///--------------------------------------------------------------------
/// --------------------------------------------------------------------
/// <seealso cref="M:log4net.Appender.AppenderSkeleton.ActivateOptions()" />
/// --------------------------------------------------------------------
public override void ActivateOptions()
{
base.ActivateOptions();
OnConfigChange();
}
///--------------------------------------------------------------------

/// <summary>
/// Called when [configuration change].
/// </summary>
private void OnConfigChange()
{
try
Expand All @@ -104,7 +134,7 @@ private void OnConfigChange()
ActiveStates states = new ActiveStates();
states.RI = RILogManager.Get(InstanceName) ?? RILogManager.Default;
states.DisplayLevel = String.Compare(DisplayLevel.ToLower().Trim(), "true", false) == 0;
states.DisplayLocation = String.Compare(DisplayLocation.ToLower().Trim() , "true", false) == 0;
states.DisplayLocation = String.Compare(DisplayLocation.ToLower().Trim(), "true", false) == 0;

CurrentActiveStates = states;
}
Expand All @@ -114,12 +144,25 @@ private void OnConfigChange()
RIExceptionManager.Publish(ex, "Failed during: LogAppender.OnConfigChange()");
}
}
///--------------------------------------------------------------------
static private Boolean SendInternalError(ReflectInsight ri, MessageType mType, Exception ex)

/// <summary>
/// Sends the internal error.
/// </summary>
/// <param name="ri">The ri.</param>
/// <param name="mType">Type of the m.</param>
/// <param name="ex">The ex.</param>
/// <returns></returns>
static private Boolean SendInternalError(IReflectInsight ri, MessageType mType, Exception ex)
{
return (Boolean)FSendInternalErrorMethodInfo.Invoke(ri, new object[] { mType, ex });
}
///--------------------------------------------------------------------

/// <summary>
/// Sends the message.
/// </summary>
/// <param name="states">The states.</param>
/// <param name="mType">Type of the m.</param>
/// <param name="loggingEvent">The logging event.</param>
static private void SendMessage(ActiveStates states, MessageType mType, LoggingEvent loggingEvent)
{
try
Expand Down Expand Up @@ -163,7 +206,25 @@ static private void SendMessage(ActiveStates states, MessageType mType, LoggingE
if (!SendInternalError(states.RI, mType, ex)) throw;
}
}
///--------------------------------------------------------------------

/// <summary>
/// Subclasses of <see cref="T:log4net.Appender.AppenderSkeleton" /> should implement this method
/// to perform actual logging.
/// </summary>
/// <param name="loggingEvent">The event to append.</param>
/// <remarks>
/// <para>
/// A subclass must implement this method to perform
/// logging of the <paramref name="loggingEvent" />.
/// </para>
/// <para>This method will be called by <see cref="M:DoAppend(LoggingEvent)" />
/// if all the conditions listed for that method are met.
/// </para>
/// <para>
/// To restrict the logging of events in the appender
/// override the <see cref="M:PreAppendCheck()" /> method.
/// </para>
/// </remarks>
protected override void Append(LoggingEvent loggingEvent)
{
ActiveStates states = CurrentActiveStates;
Expand All @@ -186,7 +247,7 @@ protected override void Append(LoggingEvent loggingEvent)
}
else if (loggingEvent.Level == Level.Trace)
{
mType = MessageType.SendTrace;
mType = MessageType.SendTrace;
}
else if (loggingEvent.Level == Level.Debug
|| loggingEvent.Level == Level.Log4Net_Debug)
Expand All @@ -207,11 +268,11 @@ protected override void Append(LoggingEvent loggingEvent)
else if (loggingEvent.Level == Level.Fatal
|| loggingEvent.Level == Level.Critical)
{
mType = MessageType.SendFatal;
mType = MessageType.SendFatal;
}
else if (loggingEvent.Level == Level.Notice)
{
mType = MessageType.SendNote;
mType = MessageType.SendNote;
}
else if (loggingEvent.Level == Level.Verbose)
{
Expand All @@ -220,7 +281,20 @@ protected override void Append(LoggingEvent loggingEvent)

SendMessage(states, mType, loggingEvent);
}
///--------------------------------------------------------------------

/// <summary>
/// Tests if this appender requires a <see cref="P:log4net.Appender.AppenderSkeleton.Layout" /> to be set.
/// </summary>
/// <remarks>
/// <para>
/// In the rather exceptional case, where the appender
/// implementation admits a layout but can also work without it,
/// then the appender should return <c>true</c>.
/// </para>
/// <para>
/// This default implementation always returns <c>false</c>.
/// </para>
/// </remarks>
protected override bool RequiresLayout
{
get { return false; }
Expand Down
5 changes: 2 additions & 3 deletions src/ReflectSoftware.Insight.Extensions.Log4net 4.5.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,8 @@
<HintPath>..\packages\Newtonsoft.Json.8.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="ReflectSoftware.Insight, Version=5.6.1.1604, Culture=neutral, PublicKeyToken=c78ddbdaf1f32b08, processorArchitecture=MSIL">
<HintPath>..\packages\ReflectSoftware.Insight.5.6.1.2\lib\net45\ReflectSoftware.Insight.dll</HintPath>
<Private>True</Private>
<Reference Include="ReflectSoftware.Insight, Version=5.7.0.1705, Culture=neutral, PublicKeyToken=c78ddbdaf1f32b08, processorArchitecture=MSIL">
<HintPath>..\packages\ReflectSoftware.Insight.5.7.0.0\lib\net45\ReflectSoftware.Insight.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand Down
4 changes: 1 addition & 3 deletions src/ReflectSoftware.Insight.Extensions.Log4net.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,13 @@ You can view your log4net messages in realtime, in a rich viewer that allows you
<tags>reflectinsight logging log logfiles events log4net exception handling structured tracing trace debug diagnostic</tags>
<dependencies>
<dependency id="log4net" version="2.0.8" />
<dependency id="ReflectSoftware.Insight" version="5.6.1.2" />
<dependency id="ReflectSoftware.Insight" version="5.7.0.0" />
</dependencies>
<references>
<reference file="ReflectSoftware.Insight.Extensions.Log4net.dll" />
</references>
</metadata>
<files>
<!--<file src="bin\release\net20\ReflectSoftware.Insight.Extensions.Log4net.dll" target="lib\net20\ReflectSoftware.Insight.Extensions.Log4net.dll" />
<file src="bin\release\net40\ReflectSoftware.Insight.Extensions.Log4net.dll" target="lib\net40\ReflectSoftware.Insight.Extensions.Log4net.dll" />-->
<file src="bin\release\net45\ReflectSoftware.Insight.Extensions.Log4net.dll" target="lib\net45\ReflectSoftware.Insight.Extensions.Log4net.dll" />
</files>
</package>
2 changes: 1 addition & 1 deletion src/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
<packages>
<package id="log4net" version="2.0.8" targetFramework="net451" />
<package id="Newtonsoft.Json" version="8.0.3" targetFramework="net45" />
<package id="ReflectSoftware.Insight" version="5.6.1.2" targetFramework="net451" />
<package id="ReflectSoftware.Insight" version="5.7.0.0" targetFramework="net451" />
</packages>

0 comments on commit fc9fb32

Please sign in to comment.