Skip to content
This repository has been archived by the owner. It is now read-only.

Add sample and library performance test app #1

Merged
merged 3 commits into from Dec 6, 2016
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

add library performance test app

  • Loading branch information
shweta jain
shweta jain committed Dec 2, 2016
commit 253498c0e8fc3ef522e66f7d69f86af9eb8619ca
@@ -0,0 +1,26 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "library-performance-test-app", "library-performance-test-app\library-performance-test-app.csproj", "{950ACA28-5E61-44D2-B1E5-BB9198FB4822}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "log4net-loggly", "log4net-loggly\log4net-loggly.csproj", "{ABE2B1B6-A83C-4604-AF87-FAAC3976530D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{950ACA28-5E61-44D2-B1E5-BB9198FB4822}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{950ACA28-5E61-44D2-B1E5-BB9198FB4822}.Debug|Any CPU.Build.0 = Debug|Any CPU
{950ACA28-5E61-44D2-B1E5-BB9198FB4822}.Release|Any CPU.ActiveCfg = Release|Any CPU
{950ACA28-5E61-44D2-B1E5-BB9198FB4822}.Release|Any CPU.Build.0 = Release|Any CPU
{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}.Release|Any CPU.ActiveCfg = Release|Any CPU
{ABE2B1B6-A83C-4604-AF87-FAAC3976530D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
@@ -0,0 +1,25 @@
<?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"/>
</root>
<appender name="LogglyAppender" type="log4net.loggly.LogglyAppender, log4net-loggly">
<rootUrl value="https://logs-01.loggly.com"/>
<!--add loggly customer token here-->
<inputKey value="TOKEN"/>
<tag value="log4net-throughput"/>
<logicalThreadContextKeys value="lkey1,lkey2"/>
<!-- optional -->
<globalContextKeys value="gkey1,gkey2"/>
<!-- optional -->
</appender>
</log4net>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
</configuration>
@@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using log4net;
using log4net.loggly;

namespace library_performance_test_app
{
class Program
{
static void Main(string[] args)
{
var logger = LogManager.GetLogger(typeof(Program));
Timer t = new Timer(printLogStatus, null, 0, 3 * 1000);
for (int i = 0; i < 20000; i++)
{
logger.Info(i + ": Hi to all Serialization using Json.NET is even easier. In this next sample, a Dictionary of strings (similar to the one used above for deserialization) is declared and then serialized to JSON format.Hi to all Serialization using Json.NET is even easier. In this next sample, a Dictionary of strings (similar to the one used above for deserialization) is declared and then serialized to JSON format.");
}

Console.ReadKey();

}
static void printLogStatus(Object o)
{
Console.WriteLine(LogglyClient.getLogStatus());
GC.Collect();
}
}
}
@@ -0,0 +1,37 @@
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("library-performance-test-app")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("library-performance-test-app")]
[assembly: AssemblyCopyright("Copyright © 2016")]
[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("4e49d06d-b3f9-471d-bc47-be3f43acf60d")]

// 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")]
[assembly: log4net.Config.XmlConfigurator(Watch = true)]
@@ -0,0 +1,73 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{950ACA28-5E61-44D2-B1E5-BB9198FB4822}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>library_performance_test_app</RootNamespace>
<AssemblyName>library-performance-test-app</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="log4net, Version=1.2.15.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
<HintPath>..\packages\log4net.2.0.5\lib\net45-full\log4net.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\log4net-loggly\log4net-loggly.csproj">
<Project>{abe2b1b6-a83c-4604-af87-faac3976530d}</Project>
<Name>log4net-loggly</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="log4net" version="2.0.5" targetFramework="net461" />
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net461" />
</packages>
@@ -0,0 +1,14 @@
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; }
}
}
@@ -0,0 +1,7 @@
namespace log4net.loggly
{
public interface ILogglyClient
{
void Send(ILogglyAppenderConfig config, string message);
}
}
@@ -0,0 +1,22 @@
using System.Collections.Generic;
using log4net.Core;
using System;

namespace log4net.loggly
{
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);

}
}
@@ -0,0 +1,102 @@
using log4net.Appender;
using log4net.Core;
using System;
using System.Collections.Generic;
using Timer = System.Timers;



namespace log4net.loggly
{
public class LogglyAppender : AppenderSkeleton
{
List<string> lstLogs = new List<string>();
string[] arr = new string[100];
public static readonly string InputKeyProperty = "LogglyInputKey";
public static ILogglyFormatter Formatter = new LogglyFormatter();
public static ILogglyClient Client = new LogglyClient();
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; } }

private LogglyAsyncHandler LogglyAsync;

public LogglyAppender()
{
LogglyAsync = new LogglyAsyncHandler();
Timer.Timer t = new Timer.Timer();
t.Interval = 20000;
t.Enabled = true;
t.Elapsed += t_Elapsed;
}

void t_Elapsed(object sender, Timer.ElapsedEventArgs e)
{
if (lstLogs.Count != 0)
{
SendAllEvents(lstLogs.ToArray());
}
}

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.

//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);
}

//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());
}
}

private void SendAllEvents(string[] events)
{
lstLogs.Clear();
String bulkLog = String.Join(System.Environment.NewLine, events);
LogglyAsync.PostMessage(bulkLog, Config);
}

}
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.