Skip to content

Commit

Permalink
Merge pull request #11 from psquickitjayant/patch-1
Browse files Browse the repository at this point in the history
Bug Fixes
  • Loading branch information
varshneyjayant committed Mar 25, 2015
2 parents 151a20d + abdb9d2 commit b04df06
Show file tree
Hide file tree
Showing 30 changed files with 9,311 additions and 7,710 deletions.
60 changes: 42 additions & 18 deletions source/log4net-loggly/LogglyFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using log4net.Core;
using Newtonsoft.Json;
using System.Dynamic;
using Newtonsoft.Json.Linq;

namespace log4net.loggly
{
Expand All @@ -23,9 +24,7 @@ public virtual void AppendAdditionalLoggingInformation(ILogglyAppenderConfig con

public virtual string ToJson(LoggingEvent loggingEvent)
{
return JsonConvert.SerializeObject(PreParse(loggingEvent), new JsonSerializerSettings(){
ReferenceLoopHandling = ReferenceLoopHandling.Ignore
});
return PreParse(loggingEvent);
}

public virtual string ToJson(IEnumerable<LoggingEvent> loggingEvents)
Expand All @@ -40,7 +39,7 @@ public virtual string ToJson(IEnumerable<LoggingEvent> loggingEvents)
/// </summary>
/// <param name="loggingEvent"></param>
/// <returns></returns>
private object PreParse(LoggingEvent loggingEvent)
private string PreParse(LoggingEvent loggingEvent)
{
//formating base logging info
dynamic _loggingInfo = new ExpandoObject();
Expand All @@ -52,25 +51,14 @@ private object PreParse(LoggingEvent loggingEvent)
_loggingInfo.loggerName = loggingEvent.LoggerName;

//handling messages
object _objInfo = null;
string _message = GetMessageAndObjectInfo(loggingEvent, out _objInfo);
object _loggedObject = null;
string _message = GetMessageAndObjectInfo(loggingEvent, out _loggedObject);

if (_message != string.Empty)
{
_loggingInfo.message = _message;
}

if (_objInfo != null)
{
var p = _loggingInfo as IDictionary<string, object>;

var _properties = _objInfo.GetType().GetProperties();
foreach (var property in _properties)
{
p[property.Name] = property.GetValue(_objInfo, null);
}
}

//handling exceptions
dynamic _exceptionInfo = GetExceptionInfo(loggingEvent);
if (_exceptionInfo != null)
Expand Down Expand Up @@ -103,7 +91,43 @@ private object PreParse(LoggingEvent loggingEvent)
}
}

return _loggingInfo;
//converting event info to Json string
var _loggingEventJSON = JsonConvert.SerializeObject(_loggingInfo,
new JsonSerializerSettings()
{
ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
});

//checking if _loggedObject is not null
//if it is not null then convert it into JSON string
//and concatenate to the _loggingEventJSON

if (_loggedObject != null)
{
//converting passed object to JSON string

var _loggedObjectJSON = JsonConvert.SerializeObject(_loggedObject,
new JsonSerializerSettings()
{
PreserveReferencesHandling = PreserveReferencesHandling.Arrays,
ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
});

//concatenating _loggedObjectJSON with _loggingEventJSON
//http://james.newtonking.com/archive/2014/08/04/json-net-6-0-release-4-json-merge-dependency-injection

JObject jEvent = JObject.Parse(_loggingEventJSON);
JObject jObject = JObject.Parse(_loggedObjectJSON);

jEvent.Merge(jObject, new JsonMergeSettings
{
MergeArrayHandling = MergeArrayHandling.Union
});

_loggingEventJSON = jEvent.ToString();
}

return _loggingEventJSON;
}

/// <summary>
Expand Down
6 changes: 3 additions & 3 deletions source/log4net-loggly/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Microsoft")]
[assembly: AssemblyProduct("log4net-loggly")]
[assembly: AssemblyCopyright("Copyright © Microsoft 2012")]
[assembly: AssemblyCopyright("Copyright © log4net-loggly 2015")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

Expand All @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("6.0.0.0")]
[assembly: AssemblyFileVersion("6.0.0.0")]
[assembly: AssemblyVersion("6.0.4.0")]
[assembly: AssemblyFileVersion("6.0.4.0")]
5 changes: 3 additions & 2 deletions source/log4net-loggly/log4net-loggly.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\log4net.2.0.3\lib\net40-full\log4net.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json">
<HintPath>..\packages\Newtonsoft.Json.6.0.4\lib\net40\Newtonsoft.Json.dll</HintPath>
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Newtonsoft.Json.6.0.8\lib\net40\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
Expand Down
3 changes: 1 addition & 2 deletions source/log4net-loggly/packages.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="log4net" version="2.0.3" targetFramework="net40" />
<package id="log4net-loggly" version="2.0.0" targetFramework="net40" />
<package id="Newtonsoft.Json" version="6.0.4" targetFramework="net40" />
<package id="Newtonsoft.Json" version="6.0.8" targetFramework="net40" />
</packages>
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit b04df06

Please sign in to comment.