class Program
{
static void Main(string[] args)
{
EnableSelfSignedCertificates();
TraceListenerExample();
}
private static void TraceListenerExample()
{
// Replace with your HEC token
string token = "here my Event Collector token";
// TraceListener
var trace = new TraceSource("MyToken");
trace.Switch.Level = SourceLevels.All;
var listener = new HttpEventCollectorTraceListener(
uri: new Uri("http://localhost:8000"),
token: token,
batchSizeCount: 1);
trace.Listeners.Add(listener);
// Send some events
trace.TraceEvent(TraceEventType.Error, 0, "hello world 0");
trace.TraceEvent(TraceEventType.Information, 1, "hello world 1");
trace.TraceData(TraceEventType.Information, 2, "hello world 2");
trace.TraceData(TraceEventType.Error, 3, "hello world 3");
trace.TraceData(TraceEventType.Information, 4, "hello world 4");
trace.Close();
// Now search splunk index that used by your HEC token you should see above 5 events are indexed
}
private static void EnableSelfSignedCertificates()
{
// Enable self signed certificates
System.Net.ServicePointManager.ServerCertificateValidationCallback +=
delegate (object sender, System.Security.Cryptography.X509Certificates.X509Certificate certificate,
System.Security.Cryptography.X509Certificates.X509Chain chain,
System.Net.Security.SslPolicyErrors sslPolicyErrors)
{
return true;
};
}
}
↧