diff --git a/source/log4net-loggly-console/App.config b/source/log4net-loggly-console/App.config index 7308018..108e1ff 100644 --- a/source/log4net-loggly-console/App.config +++ b/source/log4net-loggly-console/App.config @@ -1,16 +1,16 @@  - -
- - + +
+ + - + @@ -21,7 +21,7 @@ - + diff --git a/source/log4net-loggly-console/Program.cs b/source/log4net-loggly-console/Program.cs index b191faf..dd0f478 100644 --- a/source/log4net-loggly-console/Program.cs +++ b/source/log4net-loggly-console/Program.cs @@ -1,5 +1,7 @@ using System; using System.Collections.Generic; +using System.IO; +using System.Reflection; using System.Threading; using log4net; using log4net.Core; @@ -20,12 +22,13 @@ public override string ToString() } class Program - { + { static void Main(string[] argArray) { GlobalContext.Properties["GlobalContextPropertySample"] = new GlobalContextTest(); - log4net.Config.XmlConfigurator.Configure(); + var logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly()); + log4net.Config.XmlConfigurator.Configure(logRepository,new FileInfo("app.config")); var log = LogManager.GetLogger(typeof(Program)); @@ -77,13 +80,13 @@ static void Main(string[] argArray) }); newThread2.Start(); - + //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 { child1, child2 }; - log.Info(parent); + 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 { child1, child2 }; + log.Info(parent); log.Debug("zzzz"); log.InfoFormat("Loggly is the best {0} to collect Logs.", "service"); @@ -93,5 +96,5 @@ static void Main(string[] argArray) Console.ReadKey(); } - } + } } diff --git a/source/log4net-loggly-console/Properties/AssemblyInfo.cs b/source/log4net-loggly-console/Properties/AssemblyInfo.cs deleted file mode 100644 index 861c32f..0000000 --- a/source/log4net-loggly-console/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("log4net-loggly-console")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("Microsoft")] -[assembly: AssemblyProduct("log4net-loggly-console")] -[assembly: AssemblyCopyright("Copyright © Microsoft 2012")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("03778af1-2191-41ac-bac4-ff50069ed9b7")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// 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("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/source/log4net-loggly-console/TestObject.cs b/source/log4net-loggly-console/TestObject.cs index 4b2bf2b..ca802aa 100644 --- a/source/log4net-loggly-console/TestObject.cs +++ b/source/log4net-loggly-console/TestObject.cs @@ -1,7 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; +using System.Collections.Generic; namespace log4net_loggly_console { @@ -20,17 +17,17 @@ public TestObject() TOField4 = new { TOFF1 = "TOFFValue1", TOFF2 = "TOFFValue2" }; } } - //test self referencing - class Person - { - public string Name; - public Person Parent; - public List Children; - } + //test self referencing + class Person + { + public string Name; + public Person Parent; + public List Children; + } - class Child : Person - { - public string Name; + class Child : Person + { + public string Name; - } + } } diff --git a/source/log4net-loggly-console/log4net-loggly-console.csproj b/source/log4net-loggly-console/log4net-loggly-console.csproj index 62c71f0..836c3f8 100644 --- a/source/log4net-loggly-console/log4net-loggly-console.csproj +++ b/source/log4net-loggly-console/log4net-loggly-console.csproj @@ -1,74 +1,16 @@ - - + + - Debug - x86 - 8.0.30703 - 2.0 - {0FA10015-A535-484E-8700-C06893FCE2BB} Exe - Properties - log4net_loggly_console - log4net-loggly-console - v4.0 - Client - 512 + netcoreapp2.0 - - x86 - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - x86 - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - ..\packages\log4net.2.0.7\lib\net40-client\log4net.dll - True - - - - - - - - - - - - - - + - - Designer - - + + - - {ABE2B1B6-A83C-4604-AF87-FAAC3976530D} - log4net-loggly - + - - - \ No newline at end of file + + diff --git a/source/log4net-loggly-console/packages.config b/source/log4net-loggly-console/packages.config deleted file mode 100644 index b223501..0000000 --- a/source/log4net-loggly-console/packages.config +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/source/log4net-loggly.UnitTests/LogglyFormatterTest.cs b/source/log4net-loggly.UnitTests/LogglyFormatterTest.cs index a3fc05e..db40907 100644 --- a/source/log4net-loggly.UnitTests/LogglyFormatterTest.cs +++ b/source/log4net-loggly.UnitTests/LogglyFormatterTest.cs @@ -37,7 +37,7 @@ public void ShouldAddAHostNameProperty() var result = instance.ToJson(evt); dynamic json = JObject.Parse(result); - var hostName = (string) json.hostName; + var hostName = (string)json.hostName; hostName.Should().NotBeNullOrEmpty("because the machine name is used to set the hostname"); } @@ -51,7 +51,7 @@ public void ShouldAddALevelProperty() var result = instance.ToJson(evt); dynamic json = JObject.Parse(result); - var level = (string) json.level; + var level = (string)json.level; level.Should().StartWith("levelName", "because the level name property on the event is used"); } @@ -65,7 +65,7 @@ public void ShouldAddALoggerNameProperty() var result = instance.ToJson(evt); dynamic json = JObject.Parse(result); - var loggerName = (string) json.loggerName; + var loggerName = (string)json.loggerName; loggerName.Should().StartWith("LoggerName", "because this is the value of the LoggerName property on the event"); } @@ -79,7 +79,7 @@ public void ShouldAddAMessagePropertyForEventsWithoutMessages() var result = instance.ToJson(evt); dynamic json = JObject.Parse(result); - var message = (string) json.message; + var message = (string)json.message; message.Should() .Be("null", "because the MessageObject property is null but we want to log \"null\" to show this explicitly"); @@ -94,7 +94,7 @@ public void ShouldAddAProcessProperty() var result = instance.ToJson(evt); dynamic json = JObject.Parse(result); - var process = (string) json.process; + var process = (string)json.process; process.Should().NotBeNullOrEmpty("because the value is taken from the current process which should always be set"); } @@ -108,7 +108,7 @@ public void ShouldAddAThreadNameProperty() var result = instance.ToJson(evt); dynamic json = JObject.Parse(result); - var threadName = (string) json.threadName; + var threadName = (string)json.threadName; threadName.Should().StartWith("ThreadName", "because this is the value of the ThreadName property on the event"); } @@ -122,7 +122,7 @@ public void ShouldAddAValidTimestampProperty() var result = instance.ToJson(evt); dynamic json = JObject.Parse(result); - var timestamp = (string) json.timestamp; + var timestamp = (string)json.timestamp; DateTime voidDateTime; timestamp.Should().NotBeNullOrEmpty("because the timestamp property should always be set"); @@ -144,8 +144,8 @@ public void ShouldAddExtraPropertiesWhenMessageObjectIsAComplexType() var result = instance.ToJson(evt); dynamic json = JObject.Parse(result); - var propertyOne = (string) json.PropertyOne; - var propertyTwo = (int) json.PropertyTwo; + var propertyOne = (string)json.PropertyOne; + var propertyTwo = (int)json.PropertyTwo; propertyOne.Should().StartWith("PropertyOne", "because the value from the PropertyOne property on the complex type is used"); propertyTwo.Should().BeGreaterThan(0, "because the value of the PropertyTwo property on the complex type is used"); @@ -185,14 +185,14 @@ public void ShouldSerializeEventProperties() var key4 = json.Key4; var key5 = json.Key5; - ((string) key1).Should().StartWith("value1", "because that's the value of the event property with this key"); - ((int) key2).Should().BeGreaterThan(0, "because the key is set to a positive value in the event properties"); - ((object) key3).Should().NotBeNull("because the key is set in the event properties"); - ((string) key3.PropertyOne).Should().StartWith("PropertyOne", "because the value of the complex type should be serialized"); - ((int) key3.PropertyTwo).Should().BeGreaterThan(0, "because the value of the complex type should be serialized"); - ((object) key4).Should().NotBeNull("because the key is set in the event properties"); - ((string) key4).Should().Be("I'm a fixed type!", "because the type of this property requires fixing"); - ((object) key5).Should().BeNull("because the key is set but the value is null"); + ((string)key1).Should().StartWith("value1", "because that's the value of the event property with this key"); + ((int)key2).Should().BeGreaterThan(0, "because the key is set to a positive value in the event properties"); + ((object)key3).Should().NotBeNull("because the key is set in the event properties"); + ((string)key3.PropertyOne).Should().StartWith("PropertyOne", "because the value of the complex type should be serialized"); + ((int)key3.PropertyTwo).Should().BeGreaterThan(0, "because the value of the complex type should be serialized"); + ((object)key4).Should().NotBeNull("because the key is set in the event properties"); + ((string)key4).Should().Be("I'm a fixed type!", "because the type of this property requires fixing"); + ((object)key5).Should().BeNull("because the key is set but the value is null"); } [Fact] @@ -219,15 +219,15 @@ public void ShouldSerializeGlobalThreadContextProperties() var key4 = json.Key4; var key5 = json.Key5; - ((string) key1).Should().StartWith("value1", "because that's the value of the event property with this key"); - ((int) key2).Should().BeGreaterThan(0, "because the key is set to a positive value in the event properties"); - ((object) key3).Should().NotBeNull("because the key is set in the event properties"); - ((string) key3.PropertyOne).Should().StartWith("PropertyOne", "because the value of the complex type should be serialized"); - ((int) key3.PropertyTwo).Should().BeGreaterThan(0, "because the value of the complex type should be serialized"); - ((object) key4).Should().NotBeNull("because the key is set in the event properties"); - ((string) key4).Should().Be("I'm a fixed type!", "because the type of this property requires fixing"); - ((object) key5).Should().BeNull("because the key is set but the value is null"); - ((object) json.Key6).Should().BeNull("because this key was not marked for serialization"); + ((string)key1).Should().StartWith("value1", "because that's the value of the event property with this key"); + ((int)key2).Should().BeGreaterThan(0, "because the key is set to a positive value in the event properties"); + ((object)key3).Should().NotBeNull("because the key is set in the event properties"); + ((string)key3.PropertyOne).Should().StartWith("PropertyOne", "because the value of the complex type should be serialized"); + ((int)key3.PropertyTwo).Should().BeGreaterThan(0, "because the value of the complex type should be serialized"); + ((object)key4).Should().NotBeNull("because the key is set in the event properties"); + ((string)key4).Should().Be("I'm a fixed type!", "because the type of this property requires fixing"); + ((object)key5).Should().BeNull("because the key is set but the value is null"); + ((object)json.Key6).Should().BeNull("because this key was not marked for serialization"); } [Fact] @@ -254,15 +254,15 @@ public void ShouldSerializeLogicalThreadContextProperties() var key4 = json.Key4; var key5 = json.Key5; - ((string) key1).Should().StartWith("value1", "because that's the value of the event property with this key"); - ((int) key2).Should().BeGreaterThan(0, "because the key is set to a positive value in the event properties"); - ((object) key3).Should().NotBeNull("because the key is set in the event properties"); - ((string) key3.PropertyOne).Should().StartWith("PropertyOne", "because the value of the complex type should be serialized"); - ((int) key3.PropertyTwo).Should().BeGreaterThan(0, "because the value of the complex type should be serialized"); - ((object) key4).Should().NotBeNull("because the key is set in the event properties"); - ((string) key4).Should().Be("I'm a fixed type!", "because the type of this property requires fixing"); - ((object) key5).Should().BeNull("because the key is set but the value is null"); - ((object) json.Key6).Should().BeNull("because this key was not marked for serialization"); + ((string)key1).Should().StartWith("value1", "because that's the value of the event property with this key"); + ((int)key2).Should().BeGreaterThan(0, "because the key is set to a positive value in the event properties"); + ((object)key3).Should().NotBeNull("because the key is set in the event properties"); + ((string)key3.PropertyOne).Should().StartWith("PropertyOne", "because the value of the complex type should be serialized"); + ((int)key3.PropertyTwo).Should().BeGreaterThan(0, "because the value of the complex type should be serialized"); + ((object)key4).Should().NotBeNull("because the key is set in the event properties"); + ((string)key4).Should().Be("I'm a fixed type!", "because the type of this property requires fixing"); + ((object)key5).Should().BeNull("because the key is set but the value is null"); + ((object)json.Key6).Should().BeNull("because this key was not marked for serialization"); } [Fact] @@ -293,11 +293,11 @@ public void ShouldSerializeTheException() var exception = json.exception; - ((object) exception).Should().NotBeNull("because an exception was specified in the event"); + ((object)exception).Should().NotBeNull("because an exception was specified in the event"); - var message = (string) exception.exceptionMessage; - var type = (string) exception.exceptionType; - var stacktrace = (string) exception.stacktrace; + var message = (string)exception.exceptionMessage; + var type = (string)exception.exceptionType; + var stacktrace = (string)exception.stacktrace; message.Should().NotBeNullOrEmpty("because an argument exception has a default message"); type.Should().Be(typeof(ArgumentException).FullName, "because we logged an argument exception"); @@ -326,14 +326,14 @@ public void ShouldSerializeThreadContextProperties() var key4 = json.Key4; var key5 = json.Key5; - ((string) key1).Should().StartWith("value1", "because that's the value of the event property with this key"); - ((int) key2).Should().BeGreaterThan(0, "because the key is set to a positive value in the event properties"); - ((object) key3).Should().NotBeNull("because the key is set in the event properties"); - ((string) key3.PropertyOne).Should().StartWith("PropertyOne", "because the value of the complex type should be serialized"); - ((int) key3.PropertyTwo).Should().BeGreaterThan(0, "because the value of the complex type should be serialized"); - ((object) key4).Should().NotBeNull("because the key is set in the event properties"); - ((string) key4).Should().Be("I'm a fixed type!", "because the type of this property requires fixing"); - ((object) key5).Should().BeNull("because the key is set but the value is null"); + ((string)key1).Should().StartWith("value1", "because that's the value of the event property with this key"); + ((int)key2).Should().BeGreaterThan(0, "because the key is set to a positive value in the event properties"); + ((object)key3).Should().NotBeNull("because the key is set in the event properties"); + ((string)key3.PropertyOne).Should().StartWith("PropertyOne", "because the value of the complex type should be serialized"); + ((int)key3.PropertyTwo).Should().BeGreaterThan(0, "because the value of the complex type should be serialized"); + ((object)key4).Should().NotBeNull("because the key is set in the event properties"); + ((string)key4).Should().Be("I'm a fixed type!", "because the type of this property requires fixing"); + ((object)key5).Should().BeNull("because the key is set but the value is null"); } [Fact] @@ -351,7 +351,7 @@ public void ShouldSetMessagePropertyWhenMessageObjectIsString() var result = instance.ToJson(evt); dynamic json = JObject.Parse(result); - var message = (string) json.message; + var message = (string)json.message; message.Should().StartWith("message", "because the MessageObject property value is used"); } diff --git a/source/log4net-loggly.UnitTests/Properties/AssemblyInfo.cs b/source/log4net-loggly.UnitTests/Properties/AssemblyInfo.cs deleted file mode 100644 index d3ce06e..0000000 --- a/source/log4net-loggly.UnitTests/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,39 +0,0 @@ -using System.Reflection; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. - -[assembly: AssemblyTitle("log4net-loggly.UnitTests")] -[assembly: AssemblyDescription("Unit tests for the log4net-loggly project")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("Loggly")] -[assembly: AssemblyProduct("log4net-loggly.UnitTests")] -[assembly: AssemblyCopyright("Copyright © 2017")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. - -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM - -[assembly: Guid("3956c2cb-dab1-40a6-ac25-8ac6a6f577aa")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// 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("1.0.*")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/source/log4net-loggly.UnitTests/app.config b/source/log4net-loggly.UnitTests/app.config deleted file mode 100644 index 0cc270a..0000000 --- a/source/log4net-loggly.UnitTests/app.config +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/source/log4net-loggly.UnitTests/log4net-loggly.UnitTests.csproj b/source/log4net-loggly.UnitTests/log4net-loggly.UnitTests.csproj index e608e92..bc787a9 100644 --- a/source/log4net-loggly.UnitTests/log4net-loggly.UnitTests.csproj +++ b/source/log4net-loggly.UnitTests/log4net-loggly.UnitTests.csproj @@ -1,142 +1,25 @@ - - + + - Debug - AnyCPU - {3956C2CB-DAB1-40A6-AC25-8AC6A6F577AA} - Library - Properties - log4net_loggly.UnitTests - log4net-loggly.UnitTests - v4.6.1 - 512 - {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - 10.0 - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages - False - UnitTest + netcoreapp2.0 + + false - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - ..\packages\Castle.Core.4.0.0\lib\net45\Castle.Core.dll - True - - - ..\packages\FluentAssertions.4.19.2\lib\net45\FluentAssertions.dll - True - - - ..\packages\FluentAssertions.4.19.2\lib\net45\FluentAssertions.Core.dll - True - - - ..\packages\JetBrains.Annotations.10.3.0\lib\net\JetBrains.Annotations.dll - True - - - ..\packages\log4net.2.0.7\lib\net45-full\log4net.dll - True - - - - ..\packages\Moq.4.7.1\lib\net45\Moq.dll - True - - - ..\packages\Newtonsoft.Json.8.0.1\lib\net45\Newtonsoft.Json.dll - True - - - ..\packages\AutoFixture.3.50.2\lib\net40\Ploeh.AutoFixture.dll - True - - - - - - ..\packages\xunit.abstractions.2.0.1\lib\net35\xunit.abstractions.dll - True - - - ..\packages\xunit.assert.2.2.0\lib\netstandard1.1\xunit.assert.dll - True - - - ..\packages\xunit.extensibility.core.2.2.0\lib\netstandard1.1\xunit.core.dll - True - - - ..\packages\xunit.extensibility.execution.2.2.0\lib\net452\xunit.execution.desktop.dll - True - - - - - - - - - - - - - - - - + - - + + + + + + + + + + - - {ABE2B1B6-A83C-4604-AF87-FAAC3976530D} - log4net-loggly - + - - - - - False - - - False - - - False - - - False - - - - - - - - \ No newline at end of file + + diff --git a/source/log4net-loggly.UnitTests/packages.config b/source/log4net-loggly.UnitTests/packages.config deleted file mode 100644 index 5f16dfe..0000000 --- a/source/log4net-loggly.UnitTests/packages.config +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/source/log4net-loggly.sln b/source/log4net-loggly.sln index 40496c6..fe0e2da 100644 --- a/source/log4net-loggly.sln +++ b/source/log4net-loggly.sln @@ -1,58 +1,37 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 14 -VisualStudioVersion = 14.0.25420.1 +# Visual Studio 15 +VisualStudioVersion = 15.0.26730.10 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "log4net-loggly", "log4net-loggly\log4net-loggly.csproj", "{ABE2B1B6-A83C-4604-AF87-FAAC3976530D}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "log4net-loggly", "log4net-loggly\log4net-loggly.csproj", "{23BE5AFC-9598-4ECB-8B09-06B6D841B36D}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "log4net-loggly-console", "log4net-loggly-console\log4net-loggly-console.csproj", "{0FA10015-A535-484E-8700-C06893FCE2BB}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "log4net-loggly.UnitTests", "log4net-loggly.UnitTests\log4net-loggly.UnitTests.csproj", "{24227290-2834-4C4F-A1EA-4E5F2B28C080}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "log4net-loggly.UnitTests", "log4net-loggly.UnitTests\log4net-loggly.UnitTests.csproj", "{3956C2CB-DAB1-40A6-AC25-8AC6A6F577AA}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "log4net-loggly-console", "log4net-loggly-console\log4net-loggly-console.csproj", "{D93E92BB-9584-4374-AC06-EEE7C616DC3D}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU - Debug|Mixed Platforms = Debug|Mixed Platforms - Debug|x86 = Debug|x86 Release|Any CPU = Release|Any CPU - Release|Mixed Platforms = Release|Mixed Platforms - Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {ABE2B1B6-A83C-4604-AF87-FAAC3976530D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {ABE2B1B6-A83C-4604-AF87-FAAC3976530D}.Debug|Any CPU.Build.0 = Debug|Any CPU - {ABE2B1B6-A83C-4604-AF87-FAAC3976530D}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU - {ABE2B1B6-A83C-4604-AF87-FAAC3976530D}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU - {ABE2B1B6-A83C-4604-AF87-FAAC3976530D}.Debug|x86.ActiveCfg = Debug|Any CPU - {ABE2B1B6-A83C-4604-AF87-FAAC3976530D}.Release|Any CPU.ActiveCfg = Release|Any CPU - {ABE2B1B6-A83C-4604-AF87-FAAC3976530D}.Release|Any CPU.Build.0 = Release|Any CPU - {ABE2B1B6-A83C-4604-AF87-FAAC3976530D}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU - {ABE2B1B6-A83C-4604-AF87-FAAC3976530D}.Release|Mixed Platforms.Build.0 = Release|Any CPU - {ABE2B1B6-A83C-4604-AF87-FAAC3976530D}.Release|x86.ActiveCfg = Release|Any CPU - {0FA10015-A535-484E-8700-C06893FCE2BB}.Debug|Any CPU.ActiveCfg = Debug|x86 - {0FA10015-A535-484E-8700-C06893FCE2BB}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 - {0FA10015-A535-484E-8700-C06893FCE2BB}.Debug|Mixed Platforms.Build.0 = Debug|x86 - {0FA10015-A535-484E-8700-C06893FCE2BB}.Debug|x86.ActiveCfg = Debug|x86 - {0FA10015-A535-484E-8700-C06893FCE2BB}.Debug|x86.Build.0 = Debug|x86 - {0FA10015-A535-484E-8700-C06893FCE2BB}.Release|Any CPU.ActiveCfg = Release|x86 - {0FA10015-A535-484E-8700-C06893FCE2BB}.Release|Mixed Platforms.ActiveCfg = Release|x86 - {0FA10015-A535-484E-8700-C06893FCE2BB}.Release|Mixed Platforms.Build.0 = Release|x86 - {0FA10015-A535-484E-8700-C06893FCE2BB}.Release|x86.ActiveCfg = Release|x86 - {0FA10015-A535-484E-8700-C06893FCE2BB}.Release|x86.Build.0 = Release|x86 - {3956C2CB-DAB1-40A6-AC25-8AC6A6F577AA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {3956C2CB-DAB1-40A6-AC25-8AC6A6F577AA}.Debug|Any CPU.Build.0 = Debug|Any CPU - {3956C2CB-DAB1-40A6-AC25-8AC6A6F577AA}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU - {3956C2CB-DAB1-40A6-AC25-8AC6A6F577AA}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU - {3956C2CB-DAB1-40A6-AC25-8AC6A6F577AA}.Debug|x86.ActiveCfg = Debug|Any CPU - {3956C2CB-DAB1-40A6-AC25-8AC6A6F577AA}.Debug|x86.Build.0 = Debug|Any CPU - {3956C2CB-DAB1-40A6-AC25-8AC6A6F577AA}.Release|Any CPU.ActiveCfg = Release|Any CPU - {3956C2CB-DAB1-40A6-AC25-8AC6A6F577AA}.Release|Any CPU.Build.0 = Release|Any CPU - {3956C2CB-DAB1-40A6-AC25-8AC6A6F577AA}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU - {3956C2CB-DAB1-40A6-AC25-8AC6A6F577AA}.Release|Mixed Platforms.Build.0 = Release|Any CPU - {3956C2CB-DAB1-40A6-AC25-8AC6A6F577AA}.Release|x86.ActiveCfg = Release|Any CPU - {3956C2CB-DAB1-40A6-AC25-8AC6A6F577AA}.Release|x86.Build.0 = Release|Any CPU + {23BE5AFC-9598-4ECB-8B09-06B6D841B36D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {23BE5AFC-9598-4ECB-8B09-06B6D841B36D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {23BE5AFC-9598-4ECB-8B09-06B6D841B36D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {23BE5AFC-9598-4ECB-8B09-06B6D841B36D}.Release|Any CPU.Build.0 = Release|Any CPU + {24227290-2834-4C4F-A1EA-4E5F2B28C080}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {24227290-2834-4C4F-A1EA-4E5F2B28C080}.Debug|Any CPU.Build.0 = Debug|Any CPU + {24227290-2834-4C4F-A1EA-4E5F2B28C080}.Release|Any CPU.ActiveCfg = Release|Any CPU + {24227290-2834-4C4F-A1EA-4E5F2B28C080}.Release|Any CPU.Build.0 = Release|Any CPU + {D93E92BB-9584-4374-AC06-EEE7C616DC3D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D93E92BB-9584-4374-AC06-EEE7C616DC3D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D93E92BB-9584-4374-AC06-EEE7C616DC3D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D93E92BB-9584-4374-AC06-EEE7C616DC3D}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {E9CE8DCA-E04F-4D39-A4A9-1EB734044D8A} + EndGlobalSection EndGlobal diff --git a/source/log4net-loggly/ILogglyAppenderConfig.cs b/source/log4net-loggly/ILogglyAppenderConfig.cs index 6a63d1e..0238986 100644 --- a/source/log4net-loggly/ILogglyAppenderConfig.cs +++ b/source/log4net-loggly/ILogglyAppenderConfig.cs @@ -1,15 +1,15 @@ namespace log4net.loggly { - 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; } - int BufferSize { get; set; } - } + 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; } + int BufferSize { get; set; } + } } \ No newline at end of file diff --git a/source/log4net-loggly/ILogglyClient.cs b/source/log4net-loggly/ILogglyClient.cs index 7ebc8bd..2646adb 100644 --- a/source/log4net-loggly/ILogglyClient.cs +++ b/source/log4net-loggly/ILogglyClient.cs @@ -1,8 +1,8 @@ namespace log4net.loggly { - public interface ILogglyClient - { - void Send(ILogglyAppenderConfig config, string message); - void Send(ILogglyAppenderConfig config, string message, bool isBulk); - } + public interface ILogglyClient + { + void Send(ILogglyAppenderConfig config, string message); + void Send(ILogglyAppenderConfig config, string message, bool isBulk); + } } \ No newline at end of file diff --git a/source/log4net-loggly/ILogglyFormatter.cs b/source/log4net-loggly/ILogglyFormatter.cs index 83f99f3..0b4b023 100644 --- a/source/log4net-loggly/ILogglyFormatter.cs +++ b/source/log4net-loggly/ILogglyFormatter.cs @@ -4,19 +4,19 @@ namespace log4net.loggly { - public interface ILogglyFormatter - { - void AppendAdditionalLoggingInformation(ILogglyAppenderConfig unknown, LoggingEvent loggingEvent); - string ToJson(LoggingEvent loggingEvent); - string ToJson(IEnumerable loggingEvents); + public interface ILogglyFormatter + { + void AppendAdditionalLoggingInformation(ILogglyAppenderConfig unknown, LoggingEvent loggingEvent); + string ToJson(LoggingEvent loggingEvent); + string ToJson(IEnumerable loggingEvents); - /// - /// Merged Layout formatted log with the formatted timestamp - /// - /// - /// - /// - string ToJson(string renderedLog, DateTime timeStamp); - - } + /// + /// Merged Layout formatted log with the formatted timestamp + /// + /// + /// + /// + string ToJson(string renderedLog, DateTime timeStamp); + + } } \ No newline at end of file diff --git a/source/log4net-loggly/LogglyAppender.cs b/source/log4net-loggly/LogglyAppender.cs index 11f7993..2e6a745 100644 --- a/source/log4net-loggly/LogglyAppender.cs +++ b/source/log4net-loggly/LogglyAppender.cs @@ -8,98 +8,98 @@ namespace log4net.loggly { - public class LogglyAppender : AppenderSkeleton - { - List lstLogs = new List(); - string[] arr = new string[100]; - public readonly string InputKeyProperty = "LogglyInputKey"; - public ILogglyFormatter Formatter = new LogglyFormatter(); - public ILogglyClient Client = new LogglyClient(); - public LogglySendBufferedLogs _sendBufferedLogs = new LogglySendBufferedLogs(); - private ILogglyAppenderConfig Config = new LogglyAppenderConfig(); - public string RootUrl { set { Config.RootUrl = value; } } - public string InputKey { set { Config.InputKey = value; } } - public string UserAgent { set { Config.UserAgent = value; } } - public string LogMode { set { Config.LogMode = value; } } - public int TimeoutInSeconds { set { Config.TimeoutInSeconds = value; } } - public string Tag { set { Config.Tag = value; } } - public string LogicalThreadContextKeys { set { Config.LogicalThreadContextKeys = value; } } - public string GlobalContextKeys { set { Config.GlobalContextKeys = value; } } - public int BufferSize { set { Config.BufferSize = value; } } + public class LogglyAppender : AppenderSkeleton + { + List lstLogs = new List(); + string[] arr = new string[100]; + public readonly string InputKeyProperty = "LogglyInputKey"; + public ILogglyFormatter Formatter = new LogglyFormatter(); + public ILogglyClient Client = new LogglyClient(); + public LogglySendBufferedLogs _sendBufferedLogs = new LogglySendBufferedLogs(); + private ILogglyAppenderConfig Config = new LogglyAppenderConfig(); + public string RootUrl { set { Config.RootUrl = value; } } + public string InputKey { set { Config.InputKey = value; } } + public string UserAgent { set { Config.UserAgent = value; } } + public string LogMode { set { Config.LogMode = value; } } + public int TimeoutInSeconds { set { Config.TimeoutInSeconds = value; } } + public string Tag { set { Config.Tag = value; } } + public string LogicalThreadContextKeys { set { Config.LogicalThreadContextKeys = value; } } + public string GlobalContextKeys { set { Config.GlobalContextKeys = value; } } + public int BufferSize { set { Config.BufferSize = value; } } - private LogglyAsyncHandler LogglyAsync; + private LogglyAsyncHandler LogglyAsync; - public LogglyAppender() - { - LogglyAsync = new LogglyAsyncHandler(); - Timer.Timer t = new Timer.Timer(); - t.Interval = 5000; - t.Enabled = true; - t.Elapsed += t_Elapsed; - } + public LogglyAppender() + { + LogglyAsync = new LogglyAsyncHandler(); + Timer.Timer t = new Timer.Timer(); + t.Interval = 5000; + t.Enabled = true; + t.Elapsed += t_Elapsed; + } - void t_Elapsed(object sender, Timer.ElapsedEventArgs e) - { - if (lstLogs.Count != 0) - { - SendAllEvents(lstLogs.ToArray()); - } - _sendBufferedLogs.sendBufferedLogsToLoggly(Config, Config.LogMode == "bulk/"); - } + void t_Elapsed(object sender, Timer.ElapsedEventArgs e) + { + if (lstLogs.Count != 0) + { + SendAllEvents(lstLogs.ToArray()); + } + _sendBufferedLogs.sendBufferedLogsToLoggly(Config, Config.LogMode == "bulk/"); + } - protected override void Append(LoggingEvent loggingEvent) - { - SendLogAction(loggingEvent); - } + protected override void Append(LoggingEvent loggingEvent) + { + SendLogAction(loggingEvent); + } - private void SendLogAction(LoggingEvent loggingEvent) - { - //we should always format event in the same thread as - //many properties used in the event are associated with the current thread - //like threadname, ndc stacks, threadcontent properties etc. + private void SendLogAction(LoggingEvent loggingEvent) + { + //we should always format event in the same thread as + //many properties used in the event are associated with the current thread + //like threadname, ndc stacks, threadcontent properties etc. - //initializing a string for the formatted log - string _formattedLog = string.Empty; + //initializing a string for the formatted log + string _formattedLog = string.Empty; - //if Layout is null then format the log from the Loggly Client - if (this.Layout == null) - { - Formatter.AppendAdditionalLoggingInformation(Config, loggingEvent); - _formattedLog = Formatter.ToJson(loggingEvent); - } - else - { - _formattedLog = Formatter.ToJson(RenderLoggingEvent(loggingEvent), loggingEvent.TimeStamp); - } + //if Layout is null then format the log from the Loggly Client + if (this.Layout == null) + { + Formatter.AppendAdditionalLoggingInformation(Config, loggingEvent); + _formattedLog = Formatter.ToJson(loggingEvent); + } + else + { + _formattedLog = Formatter.ToJson(RenderLoggingEvent(loggingEvent), loggingEvent.TimeStamp); + } - //check if logMode is bulk or inputs - if (Config.LogMode == "bulk/") - { - addToBulk(_formattedLog); - } - else if (Config.LogMode == "inputs/") - { - //sending _formattedLog to the async queue - LogglyAsync.PostMessage(_formattedLog, Config); - } - } + //check if logMode is bulk or inputs + if (Config.LogMode == "bulk/") + { + addToBulk(_formattedLog); + } + else if (Config.LogMode == "inputs/") + { + //sending _formattedLog to the async queue + LogglyAsync.PostMessage(_formattedLog, Config); + } + } - public void addToBulk(string log) - { - // store all events into a array max lenght is 100 - lstLogs.Add(log.Replace("\n", "")); - if (lstLogs.Count == 100) - { - SendAllEvents(lstLogs.ToArray()); - } - } + public void addToBulk(string log) + { + // store all events into a array max lenght is 100 + lstLogs.Add(log.Replace("\n", "")); + if (lstLogs.Count == 100) + { + SendAllEvents(lstLogs.ToArray()); + } + } - private void SendAllEvents(string[] events) - { - lstLogs.Clear(); - String bulkLog = String.Join(System.Environment.NewLine, events); - LogglyAsync.PostMessage(bulkLog, Config); - } + private void SendAllEvents(string[] events) + { + lstLogs.Clear(); + String bulkLog = String.Join(System.Environment.NewLine, events); + LogglyAsync.PostMessage(bulkLog, Config); + } - } - } \ No newline at end of file + } +} \ No newline at end of file diff --git a/source/log4net-loggly/LogglyAppenderConfig.cs b/source/log4net-loggly/LogglyAppenderConfig.cs index 3d2b316..587b9fb 100644 --- a/source/log4net-loggly/LogglyAppenderConfig.cs +++ b/source/log4net-loggly/LogglyAppenderConfig.cs @@ -1,58 +1,58 @@ namespace log4net.loggly { - public class LogglyAppenderConfig : ILogglyAppenderConfig - { - private string _rootUrl; - private string _logMode; - public string RootUrl - { - get { return _rootUrl; } - set - { - //TODO: validate http and uri - _rootUrl = value; - if (!_rootUrl.EndsWith("/")) - { - _rootUrl += "/"; - } - } - } - - public string LogMode - { - get { return _logMode; } - set - { - _logMode = value; - if (!_logMode.EndsWith("/")) - { - _logMode = _logMode.ToLower() + "/"; - } - } - } - - public string InputKey { get; set; } - - public string UserAgent { get; set; } - - public int TimeoutInSeconds { get; set; } - - public string Tag { get; set; } - - public string LogicalThreadContextKeys { get; set; } - - public string GlobalContextKeys { get; set; } - - public int BufferSize { get; set; } - public LogglyAppenderConfig() - { - UserAgent = "loggly-log4net-appender"; - TimeoutInSeconds = 30; - Tag = "log4net"; - LogMode = "bulk"; - LogicalThreadContextKeys = null; - GlobalContextKeys = null; - BufferSize = 500; - } - } + public class LogglyAppenderConfig : ILogglyAppenderConfig + { + private string _rootUrl; + private string _logMode; + public string RootUrl + { + get { return _rootUrl; } + set + { + //TODO: validate http and uri + _rootUrl = value; + if (!_rootUrl.EndsWith("/")) + { + _rootUrl += "/"; + } + } + } + + public string LogMode + { + get { return _logMode; } + set + { + _logMode = value; + if (!_logMode.EndsWith("/")) + { + _logMode = _logMode.ToLower() + "/"; + } + } + } + + public string InputKey { get; set; } + + public string UserAgent { get; set; } + + public int TimeoutInSeconds { get; set; } + + public string Tag { get; set; } + + public string LogicalThreadContextKeys { get; set; } + + public string GlobalContextKeys { get; set; } + + public int BufferSize { get; set; } + public LogglyAppenderConfig() + { + UserAgent = "loggly-log4net-appender"; + TimeoutInSeconds = 30; + Tag = "log4net"; + LogMode = "bulk"; + LogicalThreadContextKeys = null; + GlobalContextKeys = null; + BufferSize = 500; + } + } } \ No newline at end of file diff --git a/source/log4net-loggly/LogglyAsyncHandler.cs b/source/log4net-loggly/LogglyAsyncHandler.cs index d699015..a2559ae 100644 --- a/source/log4net-loggly/LogglyAsyncHandler.cs +++ b/source/log4net-loggly/LogglyAsyncHandler.cs @@ -3,55 +3,55 @@ namespace log4net.loggly { - class LogglyAsyncHandler - { - // Size of the internal event queue. - //protected const int QueueSize = 32768; - protected ILogglyAppenderConfig _config; + class LogglyAsyncHandler + { + // Size of the internal event queue. + //protected const int QueueSize = 32768; + protected ILogglyAppenderConfig _config; - protected bool IsRunning = false; - //static list of all the queues the le appender might be managing. - private ConcurrentBag> _allQueues = new ConcurrentBag>(); + protected bool IsRunning = false; + //static list of all the queues the le appender might be managing. + private ConcurrentBag> _allQueues = new ConcurrentBag>(); - public ILogglyClient Client = new LogglyClient(); - public LogglyAsyncHandler() - { - Queue = new BlockingCollection(); - _allQueues.Add(Queue); - WorkerThread = new Thread(new ThreadStart(SendLogs)); - WorkerThread.Name = "Loggly Log Appender"; - WorkerThread.IsBackground = true; - } + public ILogglyClient Client = new LogglyClient(); + public LogglyAsyncHandler() + { + Queue = new BlockingCollection(); + _allQueues.Add(Queue); + WorkerThread = new Thread(new ThreadStart(SendLogs)); + WorkerThread.Name = "Loggly Log Appender"; + WorkerThread.IsBackground = true; + } - protected readonly BlockingCollection Queue; - protected Thread WorkerThread; + protected readonly BlockingCollection Queue; + protected Thread WorkerThread; - protected virtual void SendLogs() - { - if (this._config != null) - { - while (true) - { - var msg = Queue.Take(); - Client.Send(this._config, msg); - } - } - } + protected virtual void SendLogs() + { + if (this._config != null) + { + while (true) + { + var msg = Queue.Take(); + Client.Send(this._config, msg); + } + } + } - public void PostMessage(string msg, ILogglyAppenderConfig config) - { - this._config = config; - if (!IsRunning) - { - WorkerThread.Start(); - IsRunning = true; - } - if (!Queue.TryAdd(msg)) - { - Queue.Take(); - Queue.TryAdd(msg); - } - } - } + public void PostMessage(string msg, ILogglyAppenderConfig config) + { + this._config = config; + if (!IsRunning) + { + WorkerThread.Start(); + IsRunning = true; + } + if (!Queue.TryAdd(msg)) + { + Queue.Take(); + Queue.TryAdd(msg); + } + } + } } \ No newline at end of file diff --git a/source/log4net-loggly/LogglyBufferringAppender.cs b/source/log4net-loggly/LogglyBufferringAppender.cs index b6f4825..338fd4e 100644 --- a/source/log4net-loggly/LogglyBufferringAppender.cs +++ b/source/log4net-loggly/LogglyBufferringAppender.cs @@ -3,32 +3,32 @@ namespace log4net.loggly { - public class LogglyBufferringAppender : BufferingAppenderSkeleton - { - public readonly string InputKeyProperty = "LogglyInputKey"; + public class LogglyBufferringAppender : BufferingAppenderSkeleton + { + public readonly string InputKeyProperty = "LogglyInputKey"; - public ILogglyFormatter Formatter = new LogglyFormatter(); - public ILogglyClient Client = new LogglyClient(); + public ILogglyFormatter Formatter = new LogglyFormatter(); + public ILogglyClient Client = new LogglyClient(); - private ILogglyAppenderConfig Config = new LogglyAppenderConfig(); + private ILogglyAppenderConfig Config = new LogglyAppenderConfig(); - public string RootUrl { set { Config.RootUrl = value; } } - public string InputKey { set { Config.InputKey = value; } } - public string UserAgent { set { Config.UserAgent = value; } } - public string LogMode { set { Config.LogMode = value; } } - public int TimeoutInSeconds { set { Config.TimeoutInSeconds = value; } } - public string Tag { set { Config.Tag = value; } } - public int BufferSize { set { Config.BufferSize = value; } } + public string RootUrl { set { Config.RootUrl = value; } } + public string InputKey { set { Config.InputKey = value; } } + public string UserAgent { set { Config.UserAgent = value; } } + public string LogMode { set { Config.LogMode = value; } } + public int TimeoutInSeconds { set { Config.TimeoutInSeconds = value; } } + public string Tag { set { Config.Tag = value; } } + public int BufferSize { set { Config.BufferSize = value; } } - protected override void Append(LoggingEvent loggingEvent) - { - Formatter.AppendAdditionalLoggingInformation(Config, loggingEvent); - base.Append(loggingEvent); - } + protected override void Append(LoggingEvent loggingEvent) + { + Formatter.AppendAdditionalLoggingInformation(Config, loggingEvent); + base.Append(loggingEvent); + } - protected override void SendBuffer(LoggingEvent[] loggingEvents) - { - Client.Send(Config, Formatter.ToJson(loggingEvents)); - } - } + protected override void SendBuffer(LoggingEvent[] loggingEvents) + { + Client.Send(Config, Formatter.ToJson(loggingEvents)); + } + } } \ No newline at end of file diff --git a/source/log4net-loggly/LogglyClient.cs b/source/log4net-loggly/LogglyClient.cs index e376c2e..112ba13 100644 --- a/source/log4net-loggly/LogglyClient.cs +++ b/source/log4net-loggly/LogglyClient.cs @@ -6,146 +6,146 @@ namespace log4net.loggly { - public class LogglyClient : ILogglyClient - { - bool isValidToken = true; - public LogglyStoreLogsInBuffer _storeLogsInBuffer = new LogglyStoreLogsInBuffer(); - - public void setTokenValid(bool flag) - { - isValidToken = flag; - } - - public void storeLogs(string message, ILogglyAppenderConfig config, bool isBulk) - { - List messageBulk = new List(); - if (isBulk) - { - messageBulk = message.Split('\n').ToList(); - _storeLogsInBuffer.storeBulkLogs(config, messageBulk, isBulk); - } - else - { - _storeLogsInBuffer.storeInputLogs(config, message, isBulk); - } - } - - void printErrorMessage(string message) - { - Console.WriteLine("Loggly error: {0}", message); - } - - public virtual void Send(ILogglyAppenderConfig config, string message) - { - int maxRetryAllowed = 5; - int totalRetries = 0; - - string _tag = config.Tag; - bool isBulk = config.LogMode.Contains("bulk"); - - HttpWebResponse webResponse; - HttpWebRequest webRequest; - - //keeping userAgent backward compatible - if (!string.IsNullOrWhiteSpace(config.UserAgent)) - { - _tag = _tag + "," + config.UserAgent; - } - - while (isValidToken && totalRetries < maxRetryAllowed) - { - totalRetries++; - try - { - var bytes = Encoding.UTF8.GetBytes(message); - webRequest = CreateWebRequest(config, _tag); - - using (var dataStream = webRequest.GetRequestStream()) - { - dataStream.Write(bytes, 0, bytes.Length); - dataStream.Flush(); - dataStream.Close(); - } - webResponse = (HttpWebResponse)webRequest.GetResponse(); - webResponse.Close(); - break; - } - - catch (WebException e) - { - if (totalRetries == 1) - { - var response = (HttpWebResponse)e.Response; - if (response != null) - { - // Check for bad token - if (response.StatusCode == HttpStatusCode.Forbidden) - { - // set valid token flag to false - setTokenValid(false); - } - else - { - // store logs to buffer - storeLogs(message, config, isBulk); - } - printErrorMessage(e.Message); - } - else - { - // store logs to buffer - storeLogs(message, config, isBulk); - } - } - } - - finally - { - webRequest = null; - webResponse = null; - GC.Collect(); - } - } - } - - public void Send(ILogglyAppenderConfig config, string message, bool isbulk) - { - if (isValidToken) - { - string _tag = config.Tag; - - //keeping userAgent backward compatible - if (!string.IsNullOrWhiteSpace(config.UserAgent)) - { - _tag = _tag + "," + config.UserAgent; - } - var bytes = Encoding.UTF8.GetBytes(message); - var webRequest = CreateWebRequest(config, _tag); - - using (var dataStream = webRequest.GetRequestStream()) - { - dataStream.Write(bytes, 0, bytes.Length); - dataStream.Flush(); - dataStream.Close(); - } - var webResponse = (HttpWebResponse)webRequest.GetResponse(); - webResponse.Close(); - } - } - - protected virtual HttpWebRequest CreateWebRequest(ILogglyAppenderConfig config, string tag) - { - var url = String.Concat(config.RootUrl, config.LogMode, config.InputKey); - //adding userAgent as tag in the log - url = String.Concat(url, "/tag/" + tag); - HttpWebRequest request = null; - request = (HttpWebRequest)WebRequest.Create(url); - request.Method = "POST"; - request.ReadWriteTimeout = request.Timeout = config.TimeoutInSeconds * 1000; - request.UserAgent = config.UserAgent; - request.KeepAlive = true; - request.ContentType = "application/json"; - return request; - } - } + public class LogglyClient : ILogglyClient + { + bool isValidToken = true; + public LogglyStoreLogsInBuffer _storeLogsInBuffer = new LogglyStoreLogsInBuffer(); + + public void setTokenValid(bool flag) + { + isValidToken = flag; + } + + public void storeLogs(string message, ILogglyAppenderConfig config, bool isBulk) + { + List messageBulk = new List(); + if (isBulk) + { + messageBulk = message.Split('\n').ToList(); + _storeLogsInBuffer.storeBulkLogs(config, messageBulk, isBulk); + } + else + { + _storeLogsInBuffer.storeInputLogs(config, message, isBulk); + } + } + + void printErrorMessage(string message) + { + Console.WriteLine("Loggly error: {0}", message); + } + + public virtual void Send(ILogglyAppenderConfig config, string message) + { + int maxRetryAllowed = 5; + int totalRetries = 0; + + string _tag = config.Tag; + bool isBulk = config.LogMode.Contains("bulk"); + + HttpWebResponse webResponse; + HttpWebRequest webRequest; + + //keeping userAgent backward compatible + if (!string.IsNullOrWhiteSpace(config.UserAgent)) + { + _tag = _tag + "," + config.UserAgent; + } + + while (isValidToken && totalRetries < maxRetryAllowed) + { + totalRetries++; + try + { + var bytes = Encoding.UTF8.GetBytes(message); + webRequest = CreateWebRequest(config, _tag); + + using (var dataStream = webRequest.GetRequestStream()) + { + dataStream.Write(bytes, 0, bytes.Length); + dataStream.Flush(); + dataStream.Close(); + } + webResponse = (HttpWebResponse)webRequest.GetResponse(); + webResponse.Close(); + break; + } + + catch (WebException e) + { + if (totalRetries == 1) + { + var response = (HttpWebResponse)e.Response; + if (response != null) + { + // Check for bad token + if (response.StatusCode == HttpStatusCode.Forbidden) + { + // set valid token flag to false + setTokenValid(false); + } + else + { + // store logs to buffer + storeLogs(message, config, isBulk); + } + printErrorMessage(e.Message); + } + else + { + // store logs to buffer + storeLogs(message, config, isBulk); + } + } + } + + finally + { + webRequest = null; + webResponse = null; + GC.Collect(); + } + } + } + + public void Send(ILogglyAppenderConfig config, string message, bool isbulk) + { + if (isValidToken) + { + string _tag = config.Tag; + + //keeping userAgent backward compatible + if (!string.IsNullOrWhiteSpace(config.UserAgent)) + { + _tag = _tag + "," + config.UserAgent; + } + var bytes = Encoding.UTF8.GetBytes(message); + var webRequest = CreateWebRequest(config, _tag); + + using (var dataStream = webRequest.GetRequestStream()) + { + dataStream.Write(bytes, 0, bytes.Length); + dataStream.Flush(); + dataStream.Close(); + } + var webResponse = (HttpWebResponse)webRequest.GetResponse(); + webResponse.Close(); + } + } + + protected virtual HttpWebRequest CreateWebRequest(ILogglyAppenderConfig config, string tag) + { + var url = String.Concat(config.RootUrl, config.LogMode, config.InputKey); + //adding userAgent as tag in the log + url = String.Concat(url, "/tag/" + tag); + HttpWebRequest request = null; + request = (HttpWebRequest)WebRequest.Create(url); + request.Method = "POST"; + request.ReadWriteTimeout = request.Timeout = config.TimeoutInSeconds * 1000; + request.UserAgent = config.UserAgent; + request.KeepAlive = true; + request.ContentType = "application/json"; + return request; + } + } } diff --git a/source/log4net-loggly/LogglyFormatter.cs b/source/log4net-loggly/LogglyFormatter.cs index 401c36a..752e6d1 100644 --- a/source/log4net-loggly/LogglyFormatter.cs +++ b/source/log4net-loggly/LogglyFormatter.cs @@ -7,7 +7,7 @@ namespace log4net.loggly using System.Dynamic; using System.Linq; using System.Text; - using log4net.Core; + using Core; using Newtonsoft.Json; using Newtonsoft.Json.Linq; @@ -109,23 +109,13 @@ private string GetMessageAndObjectInfo(LoggingEvent loggingEvent, out object obj objInfo = null; var bytesLengthAllowedToLoggly = EVENT_SIZE; - if (loggingEvent.MessageObject != null) + if (!string.IsNullOrEmpty(loggingEvent.RenderedMessage)) { - if (loggingEvent.MessageObject is string - //if it is sent by using InfoFormat method then treat it as a string message - || loggingEvent.MessageObject.GetType().FullName == "log4net.Util.SystemStringFormat" - || loggingEvent.MessageObject.GetType().FullName.Contains("StringFormatFormattedMessage")) + message = loggingEvent.RenderedMessage; + var messageSizeInBytes = Encoding.Default.GetByteCount(message); + if (messageSizeInBytes > bytesLengthAllowedToLoggly) { - message = loggingEvent.MessageObject.ToString(); - var messageSizeInBytes = Encoding.Default.GetByteCount(message); - if (messageSizeInBytes > bytesLengthAllowedToLoggly) - { - message = message.Substring(0, bytesLengthAllowedToLoggly); - } - } - else - { - objInfo = loggingEvent.MessageObject; + message = message.Substring(0, bytesLengthAllowedToLoggly); } } else @@ -196,7 +186,7 @@ private string PreParse(LoggingEvent loggingEvent) loggingInfo.exception = exceptionInfo; } - var properties = (IDictionary) loggingInfo; + var properties = (IDictionary)loggingInfo; //handling loggingevent properties if (loggingEvent.Properties.Count > 0) @@ -206,7 +196,7 @@ private string PreParse(LoggingEvent loggingEvent) object propertyValue; if (TryGetPropertyValue(property.Value, out propertyValue)) { - properties[(string) property.Key] = propertyValue; + properties[(string)property.Key] = propertyValue; } } } diff --git a/source/log4net-loggly/LogglySendBufferedLogs.cs b/source/log4net-loggly/LogglySendBufferedLogs.cs index 19abec9..e87f018 100644 --- a/source/log4net-loggly/LogglySendBufferedLogs.cs +++ b/source/log4net-loggly/LogglySendBufferedLogs.cs @@ -5,53 +5,51 @@ namespace log4net.loggly { - public class LogglySendBufferedLogs - { - public string message = null; - public List arrayMessage = new List(); - public ILogglyClient Client = new LogglyClient(); - public LogglyClient _logClient = new LogglyClient(); - - public void sendBufferedLogsToLoggly(ILogglyAppenderConfig config, bool isBulk) - { - if (LogglyStoreLogsInBuffer.arrBufferedMessage.Count > 0) - { - int bulkModeBunch = 100; - int inputModeBunch = 1; - int logInBunch = isBulk ? bulkModeBunch : inputModeBunch; - arrayMessage = LogglyStoreLogsInBuffer.arrBufferedMessage.Take(logInBunch).ToList(); - message = isBulk ? String.Join(System.Environment.NewLine, arrayMessage) : arrayMessage[0]; - try - { - Client.Send(config, message, isBulk); - var tempList = LogglyStoreLogsInBuffer.arrBufferedMessage; - if (LogglyStoreLogsInBuffer.arrBufferedMessage.Count < arrayMessage.Count) - { - LogglyStoreLogsInBuffer.arrBufferedMessage.Clear(); - } - else - { - tempList.RemoveRange(0, arrayMessage.Count); - } - LogglyStoreLogsInBuffer.arrBufferedMessage = tempList; - } - catch (WebException e) - { - var response = (HttpWebResponse)e.Response; - if (response != null && response.StatusCode == HttpStatusCode.Forbidden) - { - _logClient.setTokenValid(false); - Console.WriteLine("Loggly error: {0}", e.Message); - return; - } - } - finally - { - arrayMessage.Clear(); - arrayMessage = null; - GC.Collect(); - } - } - } - } + public class LogglySendBufferedLogs + { + public string message = null; + public List arrayMessage = new List(); + public ILogglyClient Client = new LogglyClient(); + public LogglyClient _logClient = new LogglyClient(); + + public void sendBufferedLogsToLoggly(ILogglyAppenderConfig config, bool isBulk) + { + if (LogglyStoreLogsInBuffer.arrBufferedMessage.Count > 0) + { + int bulkModeBunch = 100; + int inputModeBunch = 1; + int logInBunch = isBulk ? bulkModeBunch : inputModeBunch; + arrayMessage = LogglyStoreLogsInBuffer.arrBufferedMessage.Take(logInBunch).ToList(); + message = isBulk ? String.Join(System.Environment.NewLine, arrayMessage) : arrayMessage[0]; + try + { + Client.Send(config, message, isBulk); + var tempList = LogglyStoreLogsInBuffer.arrBufferedMessage; + if (LogglyStoreLogsInBuffer.arrBufferedMessage.Count < arrayMessage.Count) + { + LogglyStoreLogsInBuffer.arrBufferedMessage.Clear(); + } + else + { + tempList.RemoveRange(0, arrayMessage.Count); + } + LogglyStoreLogsInBuffer.arrBufferedMessage = tempList; + } + catch (WebException e) + { + var response = (HttpWebResponse)e.Response; + if (response != null && response.StatusCode == HttpStatusCode.Forbidden) + { + _logClient.setTokenValid(false); + Console.WriteLine("Loggly error: {0}", e.Message); + return; + } + } + finally + { + GC.Collect(); + } + } + } + } } diff --git a/source/log4net-loggly/LogglyStoreLogsInBuffer.cs b/source/log4net-loggly/LogglyStoreLogsInBuffer.cs index e4faa4a..5b4f9bd 100644 --- a/source/log4net-loggly/LogglyStoreLogsInBuffer.cs +++ b/source/log4net-loggly/LogglyStoreLogsInBuffer.cs @@ -4,25 +4,25 @@ namespace log4net.loggly { - public class LogglyStoreLogsInBuffer - { - public static List arrBufferedMessage = new List(); - - public void storeBulkLogs(ILogglyAppenderConfig config, List logs, bool isBulk) - { - if (logs.Count == 0) return; - int numberOfLogsToBeRemoved = (arrBufferedMessage.Count + logs.Count) - config.BufferSize; - if (numberOfLogsToBeRemoved > 0) arrBufferedMessage.RemoveRange(0, numberOfLogsToBeRemoved); - - arrBufferedMessage = logs.Concat(arrBufferedMessage).ToList(); - } + public class LogglyStoreLogsInBuffer + { + public static List arrBufferedMessage = new List(); - public void storeInputLogs(ILogglyAppenderConfig config, string message, bool isBulk) - { - if (message == String.Empty) return; - int numberOfLogsToBeRemoved = (arrBufferedMessage.Count + 1) - config.BufferSize; - if (numberOfLogsToBeRemoved > 0) arrBufferedMessage.RemoveRange(0, numberOfLogsToBeRemoved); - arrBufferedMessage.Add(message); - } - } + public void storeBulkLogs(ILogglyAppenderConfig config, List logs, bool isBulk) + { + if (logs.Count == 0) return; + int numberOfLogsToBeRemoved = (arrBufferedMessage.Count + logs.Count) - config.BufferSize; + if (numberOfLogsToBeRemoved > 0) arrBufferedMessage.RemoveRange(0, numberOfLogsToBeRemoved); + + arrBufferedMessage = logs.Concat(arrBufferedMessage).ToList(); + } + + public void storeInputLogs(ILogglyAppenderConfig config, string message, bool isBulk) + { + if (message == String.Empty) return; + int numberOfLogsToBeRemoved = (arrBufferedMessage.Count + 1) - config.BufferSize; + if (numberOfLogsToBeRemoved > 0) arrBufferedMessage.RemoveRange(0, numberOfLogsToBeRemoved); + arrBufferedMessage.Add(message); + } + } } diff --git a/source/log4net-loggly/Properties/AssemblyInfo.cs b/source/log4net-loggly/Properties/AssemblyInfo.cs deleted file mode 100644 index a8e4ad4..0000000 --- a/source/log4net-loggly/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,39 +0,0 @@ -using System.Reflection; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. - -[assembly: AssemblyTitle("log4net-loggly")] -[assembly: AssemblyDescription("Log4net client for Loggly Gen 2")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("log4net-loggly")] -[assembly: AssemblyProduct("log4net-loggly")] -[assembly: AssemblyCopyright("Copyright © log4net-loggly 2015")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. - -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM - -[assembly: Guid("ad4ffe16-a464-400d-9650-bc4d1c43da8f")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// 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("7.2.0.0")] -[assembly: AssemblyFileVersion("7.2.0.0")] diff --git a/source/log4net-loggly/log4net-loggly.csproj b/source/log4net-loggly/log4net-loggly.csproj index ddaedcd..6871e4d 100644 --- a/source/log4net-loggly/log4net-loggly.csproj +++ b/source/log4net-loggly/log4net-loggly.csproj @@ -1,76 +1,28 @@ - - + + - Debug - AnyCPU - 8.0.30703 - 2.0 - {ABE2B1B6-A83C-4604-AF87-FAAC3976530D} - Library - Properties - log4net.loggly - log4net-loggly - v4.0 - 512 - - - true full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 + netcoreapp2.0;net40 + true + 8.0.0 + Loggly + Loggly + http://opensource.org/licenses/MIT + Loggly + http://github.com/loggly/log4net-loggly + Custom log4Net Appender to send logs to Loggly + .NET Core 2.0 support with old .NET frameworks compatibility + Copyright 2017 + Loggly-log4net log4net appender logs + - - False - ..\packages\log4net.2.0.7\lib\net40-client\log4net.dll - - - ..\packages\Newtonsoft.Json.8.0.1\lib\net40\Newtonsoft.Json.dll - True - - - - - - - - - + + - - - - - - - - - - - - - - - - + + + - - - \ No newline at end of file + + diff --git a/source/log4net-loggly/log4net-loggly.nuspec b/source/log4net-loggly/log4net-loggly.nuspec deleted file mode 100644 index 02963bb..0000000 --- a/source/log4net-loggly/log4net-loggly.nuspec +++ /dev/null @@ -1,20 +0,0 @@ - - - - log4net-loggly - 7.2.3 - Loggly - Loggly - http://opensource.org/licenses/MIT - http://github.com/loggly/log4net-loggly - false - Custom log4Net Appender to send logs to Loggly - Decrease wait time interval for bulk mode. - Copyright 2017 - Loggly-log4net log4net appender logs - - - - - - diff --git a/source/log4net-loggly/packages.config b/source/log4net-loggly/packages.config deleted file mode 100644 index a11abe5..0000000 --- a/source/log4net-loggly/packages.config +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file