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

Refactored the library #21

Merged
merged 12 commits into from Jan 29, 2019

Refactored code, removed unused parts, added tests

  • Loading branch information
Jiří Tomek Jiri Tomek
Jiří Tomek authored and Jiri Tomek committed Jan 29, 2019
commit 2602e12218e36518e1fb07805c4aad53c351142a
@@ -21,8 +21,8 @@ Add the following code in your web.config to configure LogglyAppender in your ap
</root>
<appender name="LogglyAppender" type="log4net.loggly.LogglyAppender, log4net-loggly">
<rootUrl value="https://logs-01.loggly.com/" />
<inputKey value="your-customer-token" />
<tag value="your-custom-tag" />
<customerToken value="your-customer-token" />
<tag value="your-custom-tags-separated-by-comma" />
<logicalThreadContextKeys value="lkey1,lkey2" /> <!-- optional -->
<globalContextKeys value="gkey1,gkey2" /> <!-- optional -->
<numberOfInnerExceptions value="4"/> <!-- optional -->
@@ -139,8 +139,8 @@ dotnet add package log4net-loggly
</root>
<appender name="LogglyAppender" type="log4net.loggly.LogglyAppender, log4net-loggly">
<rootUrl value="https://logs-01.loggly.com/" />
<inputKey value="your-customer-token" />
<tag value="your-custom-tag" />
<customerToken value="your-customer-token" />
<tag value="your-custom-tags-separated-by-comma" />
<logicalThreadContextKeys value="lkey1,lkey2" /> <!-- optional -->
<globalContextKeys value="gkey1,gkey2" /> <!-- optional -->
</appender>
@@ -16,6 +16,9 @@
<logicalThreadContextKeys value="LogicalThread1,InnerLogicalThreadContext" />
<globalContextKeys value="GlobalContextPropertySample" />
<numberOfInnerExceptions value="4"/>
<!--<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger [%property{NDC1}] - %message%newline" />
</layout>-->
</appender>
<appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
<layout type="log4net.Layout.PatternLayout">
@@ -27,8 +27,9 @@ static void Main(string[] argArray)
{
GlobalContext.Properties["GlobalContextPropertySample"] = new GlobalContextTest();

var currentFileName = Path.GetFileName(Assembly.GetExecutingAssembly().Location);
var logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly());
log4net.Config.XmlConfigurator.Configure(logRepository,new FileInfo("app.config"));
log4net.Config.XmlConfigurator.Configure(logRepository, new FileInfo(currentFileName + ".config"));

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

@@ -124,7 +125,8 @@ static void Main(string[] argArray)
log.Error("Exception", e);
}

Console.ReadKey();
log.Info("This is the last message. Program will terminate now.");
log.Logger.Repository.Shutdown();
}
}
}
@@ -19,9 +19,8 @@ public static void Main(string[] args)
{
var commandLine = CommandLineArgs.Parse(args);

var client = new TestHttpClient(commandLine.SendDelay);
// use test HTTP layer
LogglyClient.HttpClient = client;
LogglyClient.WebRequestFactory = (config, url) => new TestHttpClient(commandLine.SendDelay);

var logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly());
log4net.Config.XmlConfigurator.Configure(logRepository);
@@ -46,15 +45,15 @@ public static void Main(string[] args)

watch.Stop();

Console.WriteLine("Test finished. Elasped: {0}", watch.Elapsed);
Console.WriteLine("Test finished. Elapsed: {0}, Throughput: {1} logs/s", watch.Elapsed, _count*1000 / watch.Elapsed.TotalMilliseconds);
}

private static void SendContinuously(CommandLineArgs commandLine, Exception exception)
{
long currentCount = 0;
while ((currentCount = Interlocked.Increment(ref _count)) <= commandLine.NumEvents)
{
if (currentCount % 1000 == 0)
if (currentCount % 2000 == 0)
{
Console.WriteLine("Sent: {0}", currentCount);
}
@@ -1,10 +1,11 @@
using System;
using System.IO;
using System.Net;
using System.Threading;
using log4net.loggly;

namespace log4net_loggly_stress_tool
{
internal class TestHttpClient : ILogglyHttpClient
internal class TestHttpClient : WebRequest
{
private readonly TimeSpan _sendDelay;

@@ -13,9 +14,19 @@ public TestHttpClient(TimeSpan sendDelay)
_sendDelay = sendDelay;
}

public void Send(ILogglyAppenderConfig config, string tag, string message)
public override WebResponse GetResponse()
{
Thread.Sleep(_sendDelay);
return new TestResponse();
}

public override Stream GetRequestStream()
{
return new MemoryStream();
}

private class TestResponse : WebResponse
{
}
}
}
@@ -12,6 +12,7 @@
<rootUrl value="https://fake.logs-01.loggly.com/" />
<inputKey value="your-customer-token" />
<tag value="your-custom-tag" />
<sendInterval value="00:00:00.01" />
<logicalThreadContextKeys value="lkey1,lkey2,CommonProperty" />
<!-- optional -->
<globalContextKeys value="gkey1,gkey2,CommonProperty" />
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.