Git Product home page Git Product logo

log4net.appender.splunk's People

Contributors

akselkvitberg avatar alanbarber avatar dimitrynechaev avatar janvesely-nable avatar panthus avatar sixlettervariables avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

log4net.appender.splunk's Issues

Code exits function before posting log.

We have .NET Console app that we're developling that when every it hits the response = await postEvents(token, events); it exits out of the function with out ever getting to responseCode = response.StatusCode;.
This all occurs in the HttpEvenCollectorSender.cs file, I'll post the whole function in question below:

private async Task<HttpStatusCode> PostEvents(
            List<HttpEventCollectorEventInfo> events,
            String serializedEvents)
        {
            // encode data
            HttpResponseMessage response = null;
            string serverReply = null;
            HttpStatusCode responseCode = HttpStatusCode.OK;
            try
            {
                // post data
                HttpEventCollectorHandler next = (t, e) =>
                {
                    HttpContent content = new StringContent(serializedEvents, Encoding.UTF8, HttpContentTypeMedia);
                    return httpClient.PostAsync(httpEventCollectorEndpointUri, content);
                };
                HttpEventCollectorHandler postEvents = (t, e) =>
                {
                    return middleware == null ?
                        next(t, e) : middleware(t, e, next);
                };
                response = await postEvents(token, events);
                responseCode = response.StatusCode;
                if (responseCode != HttpStatusCode.OK && response.Content != null)
                {
                    // record server reply
                    serverReply = await response.Content.ReadAsStringAsync();
                    OnError(new HttpEventCollectorException(
                        code: responseCode,
                        webException: null,
                        reply: serverReply,
                        response: response,
                        events: events
                    ));
                }
            }
            catch (HttpEventCollectorException e)
            {
                e.Events = events;
                OnError(e);
            }
            catch (Exception e)
            {                
                OnError(new HttpEventCollectorException(
                    code: responseCode,
                    webException: e,
                    reply: serverReply,
                    response: response,
                    events: events
                ));
            }
            return responseCode;
        }

I assume it's having a hard time running the function HttpEventCollectorHandler postEvents = (t, e) => { return middleware == null ? next(t, e) : middleware(t, e, next); };

I will say this function pattern I'm not familiar with, and I'm not an expert in asynchronous programming yet either.

code consistently throws "Thread is Being Aborted" error

the code was working like charm for a lot of days and suddenly when I write a small unit test to post a fake error log using Splunk appender it started to give me this Thread Being Aborted error!
I just can't figure it out.
This abort is happening on httpclient.postasync() call in the PostEvents() method in EventCollectorSender class. I can't exactly figure out which thread is being aborted!

logs are written synchronously

Currently, logs sent to HttpEventCollectorSender are flushed synchronously using FlushSync(). See

I can see this is advantageous over fire and forget in that exceptions are not lost. However, if the http requests to the Splunk system hang so does the application. Moreover, I use a mock api (WireMock) and delayed the response by a significant amount of time. The entire app hangs on any logging calls. My suggestion is to use FlushAsync().

I'd be more than happy to make a pull request for this, but I currently don't have permissions to make new branches.

Thanks!
Cory

If a culture which uses comma instead of dot as decimal separator, logging does not work

I use nb-NO culture (norwegian), which formats doubles using comma instead of dot. Splunk requires a dot as the decimal separator in the timestamp field.

In HttpEventCollectorEventInfo, the timestamp is formatted using a simple ToString("#.000"). The dot here does not actually represent a dot, but rather the decimal separator from the current culture.

To avoid this, use CultureInfo.InvariantCulture as a format provider. This uses a dot as the decimal separator.

Could you please publish version 2.2 in NuGet

Hi Alan
Thank you for merging my change. Could you please release it as version 2.2 I guess.
I guess it would solve the other issue that version 2.1 is not actually available in Nuget.
Thanks
Jan

Cannot configure the index for sent events

We're trying to incorporate this into our product, and currently we're unable to ingest logs without setting the index for the metadata. I did not see any configurable option, nor was it obvious from the source how this could be done externally.

TLS Version mismatch issue

We are trying to use this nuget package to sent logevent to Splunk HEC.
This works fine locally on developer machine, when we deploy the asp.net WebAPI dotnet version 4.8 on azure app service
its not working, we don't see the logs in Splunk HEC.

I downloaded the project and tried to figure out what might cause the issue, I was able to identify that the issue is with httpClient
TLS issue version not setting to TLS 1.2.

Error message: The underlying connection was closed: An unexpected error occurred on a send.

I modified the httpClient to always user TLS12 and took the modified DLL and referred in WebAPI project and deployed to app service and it worked!
var handler = new HttpClientHandler();
handler.SslProtocols = System.Security.Authentication.SslProtocols.Tls12;
httpClient = new HttpClient(handler,true);

It will be very help if a configuration parameter is provided to set the TLS version.

I would like to understand use of ignoreCertificateErrors, the certificate issue with Splunk server or the application
from where the Splunk HEC is called?

Thank you

Customize layout or add properties?

Whatever I do to the layout seems to be completely ignored when it gets into Splunk.

I need to add method, type, line, custom properties on LogicalThreadContext to the JSON that gets sent to Splunk.

Is there a way to tell this appender to pull those in?

Splunk URL path is ignored

Hello
Thank you for your good work with this Appender

Just wanted to report an issue where the path part of parameter "ServerUrl" is ignored.
In our Splunk setup it very important that the path is /services/collector/event
However, in your code it seems the path is always overridden with a constant definde in "HttpEventCollectorPath"

So we changed: HttpEventCollectorSender.cs line 160
this.httpEventCollectorEndpointUri = new Uri(uri, HttpEventCollectorPath);
We changed it to:
this.httpEventCollectorEndpointUri = uri.ToString().Contains(HttpEventCollectorPath) ? uri : new Uri(uri, HttpEventCollectorPath);

This is working for us now, do you want to implement that in your code?

Jan

Enabling Appender causes console output change and halts program

Using identical appender suggested in your test.

<appender name="SplunkHTTP" type="log4net.Appender.Splunk.SplunkHttpEventCollector, log4net.Appender.Splunk">
     <ServerUrl>http://myiporhost:8088/services/collector</ServerUrl>
     <Token>mytoken</Token>
     <RetriesOnError>0</RetriesOnError>
     <threshold value="DEBUG" />
     <layout type="log4net.Layout.PatternLayout">
       <conversionPattern value="%message" />
     </layout>
   </appender>

My expectation is that the console output would remain unaffected whether or not this appender is engaged, and that application performance would be unaffected. Any help would be appreciated!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.