Skip to content
This repository was archived by the owner on Jun 2, 2018. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
1bcffa5
Updated refernces versions
May 19, 2014
128e259
Delete packages.config
May 19, 2014
1151243
updated to use userAgent
May 19, 2014
34ac964
Code Formatting Updated
May 21, 2014
591a117
Added more instructions
May 21, 2014
6834ddb
Updated Dump() to ToJson()
May 23, 2014
b64dc99
Update LogglyFormatter.cs
May 23, 2014
a27a316
Support to send both plain text and custom object
Jun 2, 2014
187d465
Updated comments
Jun 2, 2014
f93b3ed
Updated to Newtonsoft.Json
Aug 23, 2014
ec6f214
Updated to Newtonsoft.Json
Aug 23, 2014
403d42b
Merge pull request #1 from psquickitjayant/loggly-dev
Aug 27, 2014
caf5c33
Update README.md
Aug 28, 2014
f12dab1
Update README.md
Aug 28, 2014
44bcdd9
Added support to tag
Nov 10, 2014
6304d66
Added support to send X-Forwarded-For Header
Nov 13, 2014
7cb4f3a
Async Http Request
Nov 20, 2014
ad5dc7c
Added Support for Aysnchronous Logging and Retry upto 5 times
Dec 18, 2014
91e11aa
Fixed timestamp format to be parsed in Loggly.
Dec 30, 2014
13b607c
Now sending RenderedMessage to Loggly. Should cover both string messa…
urigrumble Jan 14, 2015
38351b5
Revert "Now sending RenderedMessage to Loggly. Should cover both stri…
urigrumble Jan 15, 2015
6fb5551
Special treatment for Common.Logging formatted messages in LogglyForm…
urigrumble Jan 15, 2015
8eaa9c8
Merge pull request #3 from RumbleInc/devs/urig/formatted_messages
varshneyjayant Jan 19, 2015
323dd10
Sends objects having value.
Jan 19, 2015
a86d9db
Added support to NDC Stack
Jan 19, 2015
a6d0af9
Bug Fixes
Jan 21, 2015
a08d520
Added support for log4net.ThreadContext.Properties
Jan 23, 2015
033c784
Re-factored Code
Jan 24, 2015
c117134
Merge pull request #4 from psquickitjayant/BOptimization
varshneyjayant Jan 28, 2015
0b703a5
fix for self refrencing bug :
giladwe Jan 28, 2015
599e295
test self referencing bug
giladwe Jan 28, 2015
d85ce02
Merge pull request #5 from giladwe/master
varshneyjayant Jan 28, 2015
8dd7ae7
Merge pull request #6 from psquickitjayant/optimization
varshneyjayant Jan 28, 2015
af87be2
Added Support to log4net.Util.ThreadStack
Jan 28, 2015
9cd25fa
Ignoring Reference Loop
Jan 29, 2015
863eb87
Adding custom object properties to main event
Jan 29, 2015
2487cb9
Merge pull request #7 from psquickitjayant/objectEvents
varshneyjayant Jan 30, 2015
38cacdd
Fixed null message issue
Feb 9, 2015
91042cd
Added check to make sure _threadContextProperties is not null
jgarcilazo Feb 19, 2015
b50dc9c
Merge pull request #10 from jgarcilazo/master
varshneyjayant Feb 24, 2015
df5c485
Update README
varshneyjayant Mar 4, 2015
f351048
Added Loggly docs link
varshneyjayant Mar 4, 2015
151a20d
Added async info in README
varshneyjayant Mar 5, 2015
88287be
Bug Fixes
Mar 20, 2015
abdb9d2
Updated to JSON.Net 6.0.8
Mar 20, 2015
b04df06
Merge pull request #11 from psquickitjayant/patch-1
varshneyjayant Mar 25, 2015
ee97728
Support to Layout Patterns
Apr 13, 2015
ed364e9
Update README
varshneyjayant Apr 13, 2015
8a05cf5
Fix indentation
varshneyjayant Apr 13, 2015
86e6892
Json type conversion pattern properties should be merged to main level
Apr 28, 2015
b3a1af3
Updated version number to 7.0
May 1, 2015
12cc099
Merge pull request #13 from psquickitjayant/conversion-pattern-support
varshneyjayant May 26, 2015
d523736
Added support for LogicalThread and Global context properties
Jan 2, 2016
d2f2452
Updated information about logical thread and global context
varshneyjayant Jan 2, 2016
00c9074
Updated formatting
varshneyjayant Jan 2, 2016
0fc54c9
Added details for GlobalContext and LogicalThreadContext
varshneyjayant Jan 6, 2016
b4e9eec
Merge pull request #19 from psquickitjayant/adding-contexts
varshneyjayant Jan 20, 2016
e472728
update to version 7.1.0
Jan 20, 2016
6e01fe0
Added Bulk Mode Support With Better Thread Handling
varshneyjayant Apr 27, 2016
26abe34
Updated doc for logMode
varshneyjayant May 17, 2016
d31ec5d
formatting fix
varshneyjayant May 17, 2016
b4dd17f
changed version to 7.2
May 17, 2016
0b2b681
Merge pull request #22 from psquickitjayant/develop
varshneyjayant Jun 2, 2016
898f78e
Bug fix
varshneyjayant Jun 27, 2016
89bc736
Update README.md
mostlyjason Nov 30, 2017
5f6aef5
Merge pull request #31 from mostlyjason/patch-1
varshneyjayant Dec 1, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
log4net-loggly
==============

Custom log4net appenders for importing logging events to loggly.
This fork is not maintained. Please see the official version at https://github.com/loggly/log4net-loggly, and Loggly's documentation at https://www.loggly.com/docs/net-logs/.
50 changes: 26 additions & 24 deletions source/log4net-loggly-console/App.config
Original file line number Diff line number Diff line change
@@ -1,31 +1,33 @@
<?xml version="1.0" encoding="utf-8" ?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
</configSections>
<log4net>
<root>
<level value="ALL" />
<appender-ref ref="LogglyAppender" />
<appender-ref ref="ColoredConsoleAppender" />
</root>
<appender name="ColoredConsoleAppender" type="log4net.Appender.ColoredConsoleAppender">
<mapping>
<level value="ERROR" />
<foreColor value="White" />
<backColor value="Red, HighIntensity" />
</mapping>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
</layout>
</appender>
<appender name="LogglyAppender" type="log4net.loggly.LogglyAppender, log4net-loggly">
<rootUrl value="https://logs.loggly.com/" />
<inputKey value="eb952942-e7c0-4f37-9746-8f018d329595" />
</appender>
<appender name="LogglyBufferringAppender" type="log4net.loggly.LogglyBufferringAppender, log4net-loggly">
<rootUrl value="https://logs.loggly.com/" />
<inputKey value="eb952942-e7c0-4f37-9746-8f018d329595" />
</appender>
<root>
<level value="ALL" />
<appender-ref ref="LogglyAppender" />
<appender-ref ref="ConsoleAppender" />
</root>
<appender name="LogglyAppender" type="log4net.loggly.LogglyAppender, log4net-loggly">
<rootUrl value="http://logs-01.loggly.com/" />
<inputKey value="customer-token" />
<tag value="log4net-test" />
<logicalThreadContextKeys value="LogicalThread1,InnerLogicalThreadContext" />
<globalContextKeys value="GlobalContextPropertySample" />
</appender>
<appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger [%property{NDC1}] - %message%newline" />
</layout>
</appender>
</log4net>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="log4net" publicKeyToken="669e0ddf0bb1aa2a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.2.11.0" newVersion="1.2.11.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
143 changes: 87 additions & 56 deletions source/log4net-loggly-console/Program.cs
Original file line number Diff line number Diff line change
@@ -1,66 +1,97 @@
using System;
using System.Collections.Generic;
using System.Threading;
using log4net;
using log4net.Core;

namespace log4net_loggly_console
{
class Program
class GlobalContextTest : IFixingRequired
{
public object GetFixedObject()
{
return ToString();
}

public override string ToString()
{
return DateTime.UtcNow.Millisecond.ToString();
}
}

class Program
{
static void Main(string[] argArray)
{
log4net.Config.XmlConfigurator.Configure();
static void Main(string[] argArray)
{
GlobalContext.Properties["GlobalContextPropertySample"] = new GlobalContextTest();

log4net.Config.XmlConfigurator.Configure();

var log = LogManager.GetLogger(typeof(Program));

Thread thread = Thread.CurrentThread;
thread.Name = "Main Thread";
ThreadContext.Properties["MainThreadContext"] = "MainThreadContextValue";
log.Info("Thread test");
log.Error("oops", new ArgumentOutOfRangeException("argArray"));
log.Warn("hmmm", new ApplicationException("app exception"));
log.Info("yawn");

Thread newThread1 = new Thread(() =>
{
Thread curntThread = Thread.CurrentThread;
curntThread.Name = "Inner thread 1";
ThreadContext.Properties["InnerThread1Context"] = "InnerThreadContext1Values";
LogicalThreadContext.Properties["InnerLogicalThreadContext"] = "InnerLogicalThreadContextValues";

using (ThreadContext.Stacks["NDC1"].Push("StackValue1"))
{
log.Info("this is an inner thread 1");

using (ThreadContext.Stacks["NDC1"].Push("StackValue2"))
{
log.Info("inner ndc of inner thread 1");
}
}

using (LogicalThreadContext.Stacks["LogicalThread1"].Push("LogicalThread1_Stack"))
{
log.Info("logical thread context 1 stack");
using (LogicalThreadContext.Stacks["LogicalThread1"].Push("LogicalThread1_Stack_2"))
{
log.Info("logical thread context 2 stack");
}
}

log.Info("without ndc of inner thread 1");
});

newThread1.Start();

Thread newThread2 = new Thread(() =>
{
Thread curntThread = Thread.CurrentThread;
curntThread.Name = "Inner thread 2";
ThreadContext.Properties["InnerThread2Context"] = "InnerThreadContext2Values";
log.Info("this is an inner thread 2");
});

newThread2.Start();

var log = LogManager.GetLogger(typeof (Program));

var args = ParseArgs(argArray);
for (int i = 0; i < args.Repeat; i++)
{
try
{
log.Error("oops", new ArgumentOutOfRangeException("argArray"));
log.Warn("hmmm", new ApplicationException("app exception"));
log.Info("yawn");
log.Debug("zzzz");
}
catch (Exception e)
{
Console.WriteLine(e);
}
}

Thread.Sleep(10000);
}

private static Args ParseArgs(string[] argArray)
{
var args = new Args{Repeat = 1};
Action<string> nextArg = null;
foreach (var a in argArray)
{
if (nextArg != null)
{
nextArg(a);
nextArg = null;
continue;
}
if (a.StartsWith("-") || a.StartsWith("/"))
{
switch (a.Substring(1))
{
case "r":
nextArg = s => args.Repeat = int.Parse(s);
break;
default:
throw new ArgumentOutOfRangeException("unknown arg: " + a);
}
}
}
return args;
}

public class Args
{
public int Repeat { get; set; }
}
//Test self referencing
var parent = new Person { Name = "John Smith" };
var child1 = new Person { Name = "Bob Smith", Parent = parent };
var child2 = new Person { Name = "Suzy Smith", Parent = parent };
parent.Children = new List<Person> { child1, child2 };
log.Info(parent);

log.Debug("zzzz");
log.InfoFormat("Loggly is the best {0} to collect Logs.", "service");
log.Info(new { type1 = "newcustomtype", value1 = "newcustomvalue" });
log.Info(new TestObject());
log.Info(null);

Console.ReadKey();
}
}
}
36 changes: 36 additions & 0 deletions source/log4net-loggly-console/TestObject.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace log4net_loggly_console
{
class TestObject
{
public string TField1 { get; set; }
public string TField2 { get; set; }
public string TField3 { get; set; }
public object TOField4 { get; set; }

public TestObject()
{
TField1 = "testValue1";
TField2 = "testValue2";
TField3 = string.Empty;
TOField4 = new { TOFF1 = "TOFFValue1", TOFF2 = "TOFFValue2" };
}
}
//test self referencing
class Person
{
public string Name;
public Person Parent;
public List<Person> Children;
}

class Child : Person
{
public string Name;

}
}
6 changes: 2 additions & 4 deletions source/log4net-loggly-console/log4net-loggly-console.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,7 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="log4net">
<HintPath>..\packages\log4net.2.0.0\lib\net40-client\log4net.dll</HintPath>
</Reference>
<Reference Include="ServiceStack.Text">
<HintPath>..\packages\ServiceStack.Text.3.8.5\lib\net35\ServiceStack.Text.dll</HintPath>
<HintPath>..\packages\log4net.2.0.3\lib\net40-client\log4net.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand All @@ -51,6 +48,7 @@
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TestObject.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config">
Expand Down
1 change: 0 additions & 1 deletion source/log4net-loggly-console/packages.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="log4net" version="2.0.0" targetFramework="net40-Client" />
<package id="ServiceStack.Text" version="3.8.5" targetFramework="net40-Client" />
</packages>
4 changes: 4 additions & 0 deletions source/log4net-loggly/ILogglyAppenderConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ public interface ILogglyAppenderConfig
string RootUrl { get; set; }
string InputKey { get; set; }
string UserAgent { get; set; }
string LogMode { get; set; }
int TimeoutInSeconds { get; set; }
string Tag { get; set; }
string LogicalThreadContextKeys { get; set; }
string GlobalContextKeys { get; set; }
}
}
2 changes: 1 addition & 1 deletion source/log4net-loggly/ILogglyClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ namespace log4net.loggly
{
public interface ILogglyClient
{
void Send(ILogglyAppenderConfig config, string inputKey, string message);
void Send(ILogglyAppenderConfig config, string message);
}
}
10 changes: 10 additions & 0 deletions source/log4net-loggly/ILogglyFormatter.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using log4net.Core;
using System;

namespace log4net.loggly
{
Expand All @@ -8,5 +9,14 @@ public interface ILogglyFormatter
void AppendAdditionalLoggingInformation(ILogglyAppenderConfig unknown, LoggingEvent loggingEvent);
string ToJson(LoggingEvent loggingEvent);
string ToJson(IEnumerable<LoggingEvent> loggingEvents);

/// <summary>
/// Merged Layout formatted log with the formatted timestamp
/// </summary>
/// <param name="renderedLog"></param>
/// <param name="timeStamp"></param>
/// <returns></returns>
string ToJson(string renderedLog, DateTime timeStamp);

}
}
Loading