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

Change, It's now possible to configure number of inner exceptions to be sent #14

Merged
merged 2 commits into from Nov 14, 2018
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

Merge branch 'master' into change/number-of-innerexceptions

  • Loading branch information
Katulus committed Nov 14, 2018
commit 7227b842e8ac45d628890622b95a9eb566b3a6bc
@@ -25,27 +25,11 @@ Add the following code in your web.config to configure LogglyAppender in your ap
<tag value="your-custom-tag" />
<logicalThreadContextKeys value="lkey1,lkey2" /> <!-- optional -->
<globalContextKeys value="gkey1,gkey2" /> <!-- optional -->
<numberOfInnerExceptions value="4"/> <!-- optional -->
</appender>
</log4net>
```
<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/" />
<inputKey value="your-customer-token" />
<tag value="your-custom-tag" />
<logicalThreadContextKeys value="lkey1,lkey2" /> <!-- optional -->
<globalContextKeys value="gkey1,gkey2" /> <!-- optional -->
<numberOfInnerExceptions value value="4"/> <!-- optional -->
</appender>
</log4net>
```

To send **GlobalContext** and **LogicalThreadContext** properties in your log you need define the list of used properties in the configuration.

For GlobalContext Properties use
@@ -1,16 +1,16 @@
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; }
int NumberOfInnerExceptions { get; set; }
}
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; }
int NumberOfInnerExceptions { get; set; }
}
}
@@ -1,106 +1,106 @@
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 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 int NumberOfInnerExceptions { set { Config.NumberOfInnerExceptions = value; } }

private LogglyAsyncHandler LogglyAsync;

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

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

}
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 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 int NumberOfInnerExceptions { set { Config.NumberOfInnerExceptions = value; } }

private LogglyAsyncHandler LogglyAsync;

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

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

}
}
You are viewing a condensed version of this merge commit. You can view the full changes here.
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.