Skip to content

Commit 709d2a5

Browse files
authored
Merge pull request #46 from splunk/example
Example:add tracelistener example
2 parents fea7c1f + f4e4b90 commit 709d2a5

File tree

7 files changed

+180
-1
lines changed

7 files changed

+180
-1
lines changed

Splunk.Logging.sln

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio 2017
3+
# Visual Studio 15
44
VisualStudioVersion = 15.0
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{5142E63D-CF4A-48EA-8527-F6B2DB4718C0}"
@@ -25,6 +25,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Splunk.Logging.Common", "sr
2525
EndProject
2626
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "standalone-test", "standalone-test\standalone-test.csproj", "{027FFE79-69FE-4A69-8B71-7364F9D1D99B}"
2727
EndProject
28+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "examples", "examples\examples.csproj", "{05F10C76-EB18-4413-98DA-B62A574E1D9B}"
29+
EndProject
2830
Global
2931
GlobalSection(SolutionConfigurationPlatforms) = preSolution
3032
Debug|Any CPU = Debug|Any CPU
@@ -51,6 +53,10 @@ Global
5153
{027FFE79-69FE-4A69-8B71-7364F9D1D99B}.Debug|Any CPU.Build.0 = Debug|Any CPU
5254
{027FFE79-69FE-4A69-8B71-7364F9D1D99B}.Release|Any CPU.ActiveCfg = Release|Any CPU
5355
{027FFE79-69FE-4A69-8B71-7364F9D1D99B}.Release|Any CPU.Build.0 = Release|Any CPU
56+
{05F10C76-EB18-4413-98DA-B62A574E1D9B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
57+
{05F10C76-EB18-4413-98DA-B62A574E1D9B}.Debug|Any CPU.Build.0 = Debug|Any CPU
58+
{05F10C76-EB18-4413-98DA-B62A574E1D9B}.Release|Any CPU.ActiveCfg = Release|Any CPU
59+
{05F10C76-EB18-4413-98DA-B62A574E1D9B}.Release|Any CPU.Build.0 = Release|Any CPU
5460
EndGlobalSection
5561
GlobalSection(SolutionProperties) = preSolution
5662
HideSolutionNode = FALSE
@@ -62,4 +68,7 @@ Global
6268
{B776A5C5-A301-472E-9D21-A62306358B2C} = {5142E63D-CF4A-48EA-8527-F6B2DB4718C0}
6369
{027FFE79-69FE-4A69-8B71-7364F9D1D99B} = {2F34BC99-9753-46CC-A386-33B543EFF916}
6470
EndGlobalSection
71+
GlobalSection(ExtensibilityGlobals) = postSolution
72+
SolutionGuid = {94C12565-E78F-448C-95F0-D0D0EACAE996}
73+
EndGlobalSection
6574
EndGlobal

examples/App.config

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
5+
</startup>
6+
<runtime>
7+
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
8+
<dependentAssembly>
9+
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
10+
<bindingRedirect oldVersion="0.0.0.0-11.0.0.0" newVersion="11.0.0.0" />
11+
</dependentAssembly>
12+
</assemblyBinding>
13+
</runtime>
14+
</configuration>

examples/Program.cs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
using Splunk.Logging;
2+
using System;
3+
using System.Diagnostics;
4+
5+
namespace examples
6+
{
7+
class Program
8+
{
9+
static void Main(string[] args)
10+
{
11+
EnableSelfSignedCertificates();
12+
13+
TraceListenerExample();
14+
}
15+
16+
private static void TraceListenerExample()
17+
{
18+
// Replace with your HEC token
19+
string token = "1ff51387-405a-4566-9f6a-87bc3fb44424";
20+
21+
// TraceListener
22+
var trace = new TraceSource("demo-logger");
23+
trace.Switch.Level = SourceLevels.All;
24+
var listener = new HttpEventCollectorTraceListener(
25+
uri: new Uri("https://127.0.0.1:8088"),
26+
token: token,
27+
batchSizeCount: 1);
28+
trace.Listeners.Add(listener);
29+
30+
// Send some events
31+
trace.TraceEvent(TraceEventType.Error, 0, "hello world 0");
32+
trace.TraceEvent(TraceEventType.Information, 1, "hello world 1");
33+
trace.TraceData(TraceEventType.Information, 2, "hello world 2");
34+
trace.TraceData(TraceEventType.Error, 3, "hello world 3");
35+
trace.TraceData(TraceEventType.Information, 4, "hello world 4");
36+
trace.Close();
37+
38+
// Now search splunk index that used by your HEC token you should see above 5 events are indexed
39+
}
40+
41+
private static void EnableSelfSignedCertificates()
42+
{
43+
// Enable self signed certificates
44+
System.Net.ServicePointManager.ServerCertificateValidationCallback +=
45+
delegate (object sender, System.Security.Cryptography.X509Certificates.X509Certificate certificate,
46+
System.Security.Cryptography.X509Certificates.X509Chain chain,
47+
System.Net.Security.SslPolicyErrors sslPolicyErrors)
48+
{
49+
return true;
50+
};
51+
}
52+
}
53+
}

examples/Properties/AssemblyInfo.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("examples")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("examples")]
13+
[assembly: AssemblyCopyright("Copyright © 2019")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("05f10c76-eb18-4413-98da-b62a574e1d9b")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]

examples/examples.csproj

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{05F10C76-EB18-4413-98DA-B62A574E1D9B}</ProjectGuid>
8+
<OutputType>Exe</OutputType>
9+
<RootNamespace>examples</RootNamespace>
10+
<AssemblyName>examples</AssemblyName>
11+
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
12+
<FileAlignment>512</FileAlignment>
13+
<Deterministic>true</Deterministic>
14+
</PropertyGroup>
15+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
16+
<PlatformTarget>AnyCPU</PlatformTarget>
17+
<DebugSymbols>true</DebugSymbols>
18+
<DebugType>full</DebugType>
19+
<Optimize>false</Optimize>
20+
<OutputPath>bin\Debug\</OutputPath>
21+
<DefineConstants>DEBUG;TRACE</DefineConstants>
22+
<ErrorReport>prompt</ErrorReport>
23+
<WarningLevel>4</WarningLevel>
24+
</PropertyGroup>
25+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
26+
<PlatformTarget>AnyCPU</PlatformTarget>
27+
<DebugType>pdbonly</DebugType>
28+
<Optimize>true</Optimize>
29+
<OutputPath>bin\Release\</OutputPath>
30+
<DefineConstants>TRACE</DefineConstants>
31+
<ErrorReport>prompt</ErrorReport>
32+
<WarningLevel>4</WarningLevel>
33+
</PropertyGroup>
34+
<ItemGroup>
35+
<Reference Include="System" />
36+
<Reference Include="Microsoft.CSharp" />
37+
</ItemGroup>
38+
<ItemGroup>
39+
<Compile Include="Program.cs" />
40+
<Compile Include="Properties\AssemblyInfo.cs" />
41+
</ItemGroup>
42+
<ItemGroup>
43+
<None Include="App.config" />
44+
<None Include="packages.config" />
45+
</ItemGroup>
46+
<ItemGroup>
47+
<ProjectReference Include="..\src\Splunk.Logging.Common\Splunk.Logging.Common.csproj">
48+
<Project>{b776a5c5-a301-472e-9d21-a62306358b2c}</Project>
49+
<Name>Splunk.Logging.Common</Name>
50+
</ProjectReference>
51+
<ProjectReference Include="..\src\Splunk.Logging.TraceListener\Splunk.Logging.TraceListener.csproj">
52+
<Project>{17f12964-d0c9-41a9-9dee-a4a5a52b24ae}</Project>
53+
<Name>Splunk.Logging.TraceListener</Name>
54+
</ProjectReference>
55+
</ItemGroup>
56+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
57+
</Project>

examples/packages.config

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="EnterpriseLibrary.SemanticLogging" version="2.0.1406.1" targetFramework="net45" />
4+
<package id="Newtonsoft.Json" version="11.0.2" targetFramework="net45" />
5+
</packages>

standalone-test/packages.config

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="EnterpriseLibrary.SemanticLogging" version="2.0.1406.1" targetFramework="net45" />
4+
<package id="Newtonsoft.Json" version="5.0.8" targetFramework="net45" />
5+
</packages>

0 commit comments

Comments
 (0)