Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing handling for LoggingEvent properties #7

Merged
Next

Added missing handling for LoggingEvent properties

Occasionally we need properties tied to a specific event and not a ThreadContext which is shared across the entire thread. This hooks into the built in functionality in log4net for this scenario.
  • Loading branch information
Asbjørn Hansen
Asbjørn Hansen committed Mar 3, 2017
commit 67fe12625cad98dd37766f29c53aa9e5d4deac5b
@@ -7,6 +7,7 @@
using System.Dynamic;
using Newtonsoft.Json.Linq;
using System.Text;
using System.Collections;

namespace log4net.loggly
{
@@ -75,6 +76,27 @@ private string PreParse(LoggingEvent loggingEvent)
_loggingInfo.exception = _exceptionInfo;
}

//handling loggingevent properties
if(loggingEvent.Properties.Count > 0)
{
var properties = (IDictionary<string, object>)_loggingInfo;
foreach(DictionaryEntry property in loggingEvent.Properties)
{
var fixedProperty = property.Value as IFixingRequired;
object propertyValue;
if(fixedProperty != null && fixedProperty.GetFixedObject() != null)
{
propertyValue = fixedProperty.GetFixedObject();
}
else
{
propertyValue = property.Value;
}

properties[(string)property.Key] = propertyValue;
}
}

//handling threadcontext properties
string[] _threadContextProperties = ThreadContext.Properties.GetKeys();
if (_threadContextProperties != null && _threadContextProperties.Any())
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.