Dashboards & Visualizations
Highlighted

HttpEventCollectorException error C# library

Explorer

Hello everybody,

I want to use the Splunk C# library to log directly into my Splunk by Http.

But the HttpTraceEvent library just doesn't work. I have am getting an HttpEventCollectorException error.

Here is my code:

TraceSource traceSource = new TraceSource(this.sourcename);
traceSource.Switch.Level = SourceLevels.All;
traceSource.Listeners.Clear();

traceListener = new HttpEventCollectorTraceListener(uri: new Uri(target), token: token);            

traceListener.AddLoggingFailureHandler((HttpEventCollectorException e) => {
        Console.WriteLine("{0}",e);
});
traceSource.Listeners.Add(traceListener);
traceSource.TraceEvent(TraceEventType.Information, 1, "Test Message");

My variable target is "https://localhost:8088"

The example above is the same as the one in the documentation here: http://dev.splunk.com/view/splunk-loglib-dotnet/SP-CAAAEX9

So, I tried to use curl to check if it was not my token or my address that was wrong:

curl -k https://localhost:8088/services/collector/event/1.0 -H "Authorization: Splunk 35D1638E-75CB-4A6F-B314-21C959DAF466" -d "{\"event\": \"hello world\"}"

This one works as I can see my log in Splunk.

Could someone help me? Possibly a good alternative using http in C#? Thanks

0 Karma
Highlighted

Re: HttpEventCollectorException error C# library

Splunk Employee
Splunk Employee
  1. Can you show the exception message?
  2. Did you disable cert validation in your code? If not, then this is very likely the issue.
0 Karma