Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sample app #1

Merged
merged 3 commits into from Oct 11, 2018
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Adding basic sample app to blacklist fields in .NET Serilog setup

  • Loading branch information
Shweta Jain
Shweta Jain committed Oct 11, 2018
commit c309b3664b1e0634fb7a98060213db12b6df59d7
@@ -0,0 +1,35 @@
*.swp
*.*~
project.lock.json
.DS_Store
*.pyc
nupkg/
packages/

# Visual Studio Code
.vscode

# User-specific files
*.suo
*.user
*.userosscache
*.sln.docstates

# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
build/
bld/
[Bb]in/
[Oo]bj/
[Oo]ut/
msbuild.log
msbuild.err
msbuild.wrn

# Visual Studio 2015
.vs/
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27130.2010
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ExcludeFieldsNETSerilog", "ExcludeFieldsNETSerilog\ExcludeFieldsNETSerilog.csproj", "{3B4DEF1C-C5D4-4BAC-95F8-2BCA31087D25}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{3B4DEF1C-C5D4-4BAC-95F8-2BCA31087D25}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3B4DEF1C-C5D4-4BAC-95F8-2BCA31087D25}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3B4DEF1C-C5D4-4BAC-95F8-2BCA31087D25}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3B4DEF1C-C5D4-4BAC-95F8-2BCA31087D25}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {E7140C5A-C07E-4056-8184-E9A323392DC7}
EndGlobalSection
EndGlobal
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="loggly" type="Loggly.Config.LogglyAppConfig, Loggly.Config"/>
</configSections>
<loggly
xmlns="Loggly"
applicationName="ExcludeFieldsSerilog"
customerToken="CUSTOMER_TOKEN"
isEnabled="true"
throwExceptions="true">

<transport logTransport="Https" endpointHostname="logs-01.loggly.com" endpointPort="443"/>

<!--<search account="your_loggly_account" username="a_loggly_username" password="myLittleP0ny!"/>-->

<tags>
<simple>
<tag value="Serilog-FieldExclude"/>
</simple>
<!--<complex>
<tag type="Loggly.HostnameTag" formatter="host-{0}"/>
<tag type="Loggly.ApplicationNameTag" formatter="application-{0}"/>
<tag type="Loggly.OperatingSystemVersionTag" formatter="os-{0}"/>
<tag type="Loggly.OperatingSystemPlatformTag" formatter="platform-{0}"/>
</complex>-->
</tags>
</loggly>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-10.0.0.0" newVersion="10.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
@@ -0,0 +1,24 @@
using Newtonsoft.Json.Linq;
using System.Collections.Generic;

namespace ExcludeFieldsNETSerilog
{
class ExcludeFields
{
public string FirstName { get; set; }
public string LastName { get; set; }
public int EmployeeID { get; set; }
public string Designation { get; set; }
public string Address { get; set; }

public string excludeFields(string jsonString, List<string> discardedFields)
{
JObject jo = JObject.Parse(jsonString);
foreach (var discardedField in discardedFields)
{
jo.Remove(discardedField);
}
return jo.ToString(Newtonsoft.Json.Formatting.None);
}
}
}
@@ -0,0 +1,78 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{3B4DEF1C-C5D4-4BAC-95F8-2BCA31087D25}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>ExcludeFieldsNETSerilog</RootNamespace>
<AssemblyName>ExcludeFieldsNETSerilog</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Loggly, Version=4.6.1.55, Culture=neutral, PublicKeyToken=aea0e3c965ace843, processorArchitecture=MSIL">
<HintPath>..\packages\loggly-csharp.4.6.1.55\lib\net45\Loggly.dll</HintPath>
</Reference>
<Reference Include="Loggly.Config, Version=4.6.1.55, Culture=neutral, PublicKeyToken=aea0e3c965ace843, processorArchitecture=MSIL">
<HintPath>..\packages\loggly-csharp-config.4.6.1.55\lib\net45\Loggly.Config.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="Serilog, Version=2.0.0.0, Culture=neutral, PublicKeyToken=24c2f752a8e58a10, processorArchitecture=MSIL">
<HintPath>..\packages\Serilog.2.5.0\lib\net46\Serilog.dll</HintPath>
</Reference>
<Reference Include="Serilog.Sinks.File, Version=2.0.0.0, Culture=neutral, PublicKeyToken=24c2f752a8e58a10, processorArchitecture=MSIL">
<HintPath>..\packages\Serilog.Sinks.File.3.2.0\lib\net45\Serilog.Sinks.File.dll</HintPath>
</Reference>
<Reference Include="Serilog.Sinks.Loggly, Version=3.1.0.0, Culture=neutral, PublicKeyToken=24c2f752a8e58a10, processorArchitecture=MSIL">
<HintPath>..\packages\Serilog.Sinks.Loggly.5.3.0\lib\net45\Serilog.Sinks.Loggly.dll</HintPath>
</Reference>
<Reference Include="Serilog.Sinks.PeriodicBatching, Version=2.0.0.0, Culture=neutral, PublicKeyToken=24c2f752a8e58a10, processorArchitecture=MSIL">
<HintPath>..\packages\Serilog.Sinks.PeriodicBatching.2.1.1\lib\net45\Serilog.Sinks.PeriodicBatching.dll</HintPath>
</Reference>
<Reference Include="Serilog.Sinks.RollingFile, Version=2.0.0.0, Culture=neutral, PublicKeyToken=24c2f752a8e58a10, processorArchitecture=MSIL">
<HintPath>..\packages\Serilog.Sinks.RollingFile.3.3.0\lib\net45\Serilog.Sinks.RollingFile.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="ExcludeFields.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
@@ -0,0 +1,32 @@
using Loggly;
using Newtonsoft.Json;
using Serilog;
using System;
using System.Collections.Generic;

namespace ExcludeFieldsNETSerilog
{
class Program
{
static void Main(string[] args)
{
ExcludeFields ef = new ExcludeFields() { FirstName = "Jack", LastName = "Makan", EmployeeID = 100, Designation = "SSE", Address = "United States" };
List<string> discardedFieldsList = new List<string>();
discardedFieldsList.Add("FirstName");
discardedFieldsList.Add("Designation");
discardedFieldsList.Add("Address");
var log = new LoggerConfiguration()
.WriteTo.Loggly()
.CreateLogger();
ILogglyClient _loggly = new LogglyClient();
var logEvent = new LogglyEvent();
logEvent.Data.Add("message", "Simple message at {0}");
logEvent.Data.Add("context", ef.excludeFields(JsonConvert.SerializeObject(ef), discardedFieldsList));
logEvent.Data.Add("Error", new Exception("your exception message"));
for (int i = 0; i<10; i++) {
_loggly.Log(logEvent);
}
Console.ReadKey();
}
}
}
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("ExcludeFieldsNETSerilog")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ExcludeFieldsNETSerilog")]
[assembly: AssemblyCopyright("Copyright © 2018")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("3b4def1c-c5d4-4bac-95f8-2bca31087d25")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="loggly-csharp" version="4.6.1.55" targetFramework="net461" />
<package id="loggly-csharp-config" version="4.6.1.55" targetFramework="net461" />
<package id="Newtonsoft.Json" version="10.0.3" targetFramework="net461" />
<package id="Serilog" version="2.5.0" targetFramework="net461" />
<package id="Serilog.Sinks.File" version="3.2.0" targetFramework="net461" />
<package id="Serilog.Sinks.Loggly" version="5.3.0" targetFramework="net461" />
<package id="Serilog.Sinks.PeriodicBatching" version="2.1.1" targetFramework="net461" />
<package id="Serilog.Sinks.RollingFile" version="3.3.0" targetFramework="net461" />
</packages>
@@ -0,0 +1 @@
# Sample App for dotnet libraries
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.