How to create a new Splunk SDK for C# project using the Splunk extension for Visual Studio

The Splunk® SDK for C# project wizard creates a project with the Splunk SDK for C# already included and added to the project's references. It also optionally adds support for logging (with Event Tracing for Windows (ETW) and Semantic Logging Application Block (SLAB) or .NET logging with TraceListener) to Splunk Enterprise.

To create a new Splunk SDK for C# project:

  1. On the File menu, point to New, and then click Project.

  2. In the left pane of the New Project window, click Installed, Templates, Visual C#, and then Splunk

    Screen shot of the Visual Studio New Project window
  3. Select Splunk SDK for C# Project, and then click OK.

    Screen shot of the Splunk SDK for C# Project dialog box
  4. In the New Splunk SDK for C# Project dialog box:

    1. If you want to add logging support, choose a logging method from the Configure logging to Splunk via UDP popup menu. Otherwise, leave it as None.

    2. If you want to generate an example implementation, leave the Generate an example implementation checkbox selected. If you want to start from scratch, clear the checkbox.

  5. Click OK.

Your new project's solution opens automatically.

If you left the Generate an example implementation checkbox selected, you will see some basic starter code in the editor window. This code connects to a default Splunk Enterprise instance, creates a Service object, specifies a very basic search string and parameters, starts a one-shot search job, and then prints the search results one-by-one to the console.

If you chose TraceListener from the Configure logging to Splunk via UDP popup menu, then a function that configures the trace listener is added to the bottom of Class1.cs. In addition, several lines of code that call the function and write to the trace listener are added at the top of the Main function.

If you chose SLAB event sink from the Configure logging to Splunk via UDP popup menu, then a simple EventSource class is added to the bottom of Class1.cs. In addition, several lines of code that configure and write a message to the EventSource object are added to the top of the Main function.

The new project also contains the following:

  • A NuGet package reference for the Splunk SDK for C# 2.0.
  • Optional additional NuGet references for the Splunk logging library for .NET and SLAB packages, depending on whether you selected logging.

For more information about the different methods available for logging your app's activity back to Splunk Enterprise, see Splunk Logging Library for .NET.