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

Buffer support in log4net-loggly library during network outage #3

Merged
merged 4 commits into from Jan 28, 2017
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Prev

method name correction and exception logic modification

  • Loading branch information
Shwetajain148 committed Jan 25, 2017
commit a4b203ffd0b9cc1890dd934f782a683d7f560b69
@@ -9,9 +9,29 @@ namespace log4net.loggly
public class LogglyClient : ILogglyClient
{
static bool isValidToken = true;
public static void setValidInvalidFlag(bool flag)

public static void setTokenValid(bool flag)
{
isValidToken = flag;
}

void storeLogs(string message, ILogglyAppenderConfig config, bool isBulk)
{
List<string> messageBulk = new List<string>();
if (isBulk)
{
messageBulk = message.Split('\n').ToList();
LogglyStoreLogsInBuffer.storeBulkLogs(config, messageBulk, isBulk);
}
else
{
LogglyStoreLogsInBuffer.storeInputLogs(config, message, isBulk);
}
}

void printErrorMessage(string message)
{
isValidToken = flag;
Console.WriteLine("Loggly error: {0}", message);
}

public virtual void Send(ILogglyAppenderConfig config, string message)
@@ -22,7 +42,6 @@ public virtual void Send(ILogglyAppenderConfig config, string message)
string _tag = config.Tag;
bool isBulk = config.LogMode.Contains("bulk");

List<string> messageBulk = new List<string>();
//keeping userAgent backward compatible
if (!string.IsNullOrWhiteSpace(config.UserAgent))
{
@@ -43,33 +62,35 @@ public virtual void Send(ILogglyAppenderConfig config, string message)
dataStream.Flush();
dataStream.Close();
}

var webResponse = webRequest.GetResponse();
webResponse.Close();
break;
}

catch (WebException e) {
var response = (HttpWebResponse)e.Response;
if (response != null)
{
if (response.StatusCode == HttpStatusCode.Forbidden) //Check for bad token
{
setValidInvalidFlag(false);
}
if (totalRetries == 1) Console.WriteLine("Loggly error: {0}", e.Message);
}

else if (totalRetries == 1)
catch (WebException e)
{
if (totalRetries == 1)
{
if (isBulk)
var response = (HttpWebResponse)e.Response;
if (response != null)
{
messageBulk = message.Split('\n').ToList();
LogglyStoreLogsInBuffer.storeBulkLogs(config, messageBulk, isBulk);
// 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
{
LogglyStoreLogsInBuffer.storeInputLogs(config, message, isBulk);
// store logs to buffer
storeLogs(message, config, isBulk);
}
}
}
@@ -40,7 +40,7 @@ public static void sendBufferedLogsToLoggly(ILogglyAppenderConfig config, bool i
var response = (HttpWebResponse)e.Response;
if (response != null && response.StatusCode == HttpStatusCode.Forbidden)
{
LogglyClient.setValidInvalidFlag(false);
LogglyClient.setTokenValid(false);
Console.WriteLine("Loggly error: {0}", e.Message);
return;
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.