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

Flush messages on close #12

Closed
Closed
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -69,14 +69,6 @@ Send logs to Loggly using the following code
logger.Info("log message");
```
<strong>For Console Application</strong>
You should add the following statement at the end of your Main method as the log4net-loggly library is asynchronous so there needs to be time for the threads the complete logging before the application exits.
```
Console.ReadKey();
```
<strong>Added handling for LoggingEvent properties</strong>
Support for properties tied to a specific event and not a ThreadContext which is shared across the entire thread.
@@ -2,6 +2,7 @@
using log4net.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using Timer = System.Timers;


@@ -44,7 +45,7 @@ void t_Elapsed(object sender, Timer.ElapsedEventArgs e)
{
SendAllEvents(lstLogs.ToArray());
}
_sendBufferedLogs.sendBufferedLogsToLoggly(Config, Config.LogMode == "bulk/");
_sendBufferedLogs.sendBufferedLogsToLoggly(Config, IsBulkMode());
}

protected override void Append(LoggingEvent loggingEvent)
@@ -73,11 +74,11 @@ private void SendLogAction(LoggingEvent loggingEvent)
}

//check if logMode is bulk or inputs
if (Config.LogMode == "bulk/")
if (IsBulkMode())
{
addToBulk(_formattedLog);
}
else if (Config.LogMode == "inputs/")
else if (IsInputsMode())
{
//sending _formattedLog to the async queue
LogglyAsync.PostMessage(_formattedLog, Config);
@@ -101,5 +102,26 @@ private void SendAllEvents(string[] events)
LogglyAsync.PostMessage(bulkLog, Config);
}

}
}
private bool IsBulkMode()
{
return Config.LogMode == "bulk/";
}

private bool IsInputsMode()
{
return Config.LogMode == "inputs/";
}

protected override void OnClose()
{
if (IsBulkMode() && lstLogs.Any())
{
SendAllEvents(lstLogs.ToArray());
}

LogglyAsync.Flush();

base.OnClose();
}
}
}
@@ -1,4 +1,5 @@
using System.Collections.Concurrent;
using System.Linq;
using System.Threading;

namespace log4net.loggly
@@ -52,6 +53,14 @@ public void PostMessage(string msg, ILogglyAppenderConfig config)
Queue.TryAdd(msg);
}
}

public void Flush()
{
while (IsRunning && Queue.Any())
{
Thread.SpinWait(100);
}
}
}

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