smashraid / nlog.splunk Goto Github PK
View Code? Open in Web Editor NEWSplunk target to send logs in splunk
Splunk target to send logs in splunk
Write directly to MemoryStream, instead of first writing to StringBuilder and then allocating a complete string followed by a complete byte[] array, then this should improve performance:
var encoding = Encoding.UTF8;
var ms = new MemoryStream();
var jsonWriter = new StreamWriter(stream, encoding);
foreach (AsyncLogEventInfo item in logEvents)
{
string json = BuildLog(item.LogEvent);
jsonWriter.WriteLine(json);
}
jsonWriter.Flush();
ms.Position = 0;
var streamContent = new StreamContent(ms);
// TODO Consider caching the headerValue instead of allocating every time
var headerValue = new MediaTypeHeaderValue("text/plain") { CharSet = encoding.WebName };
streamContent.Headers.ContentType = headerValue;
var response = client.PostAsync(url, streamContent).Result;
When overriding this method to allow batch processing, then you need to do some extra work:
protected override void Write(AsyncLogEventInfo[] logEvents)
{
try
{
StringBuilder builder = new StringBuilder();
foreach (AsyncLogEventInfo item in logEvents)
{
string json = BuildLog(item.LogEvent);
builder.Append(json);
builder.AppendLine();
}
this.WriteLogMessage(builder.ToString());
}
catch (Exception ex)
{
foreach (AsyncLogEventInfo item in logEvents)
item.Continuation(ex); // Notify error
return;
}
foreach (AsyncLogEventInfo item in logEvents)
item.Continuation(null); // Notify success
}
Instead use string.IndexOf('.') >= 0
to check for dots
Instead allocate once, and reuse forever. See also -> https://aspnetmonsters.com/2016/08/2016-08-27-httpclientwrong/
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.