Skip to content

Commit f593799

Browse files
feat: add log event generator
1 parent 6c91b5d commit f593799

12 files changed

+308
-1
lines changed

.editorconfig

+54-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,61 @@
1+
# EditorConfig is awesome: http://EditorConfig.org
2+
3+
# top-most EditorConfig file
14
root = true
25

36
[*]
47
indent_style = space
8+
9+
[*.cs]
510
indent_size = 4
11+
insert_final_newline = true
12+
# Sort using directives with System.* appearing first
13+
dotnet_sort_system_directives_first = true
14+
# Avoid "this." and "Me." if not necessary
15+
dotnet_style_qualification_for_field = false:suggestion
16+
dotnet_style_qualification_for_property = false:suggestion
17+
dotnet_style_qualification_for_method = false:suggestion
18+
dotnet_style_qualification_for_event = false:suggestion
19+
# Use language keywords instead of framework type names for type references
20+
dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion
21+
dotnet_style_predefined_type_for_member_access = true:suggestion
22+
# Suggest more modern language features when available
23+
dotnet_style_object_initializer = true:suggestion
24+
dotnet_style_collection_initializer = true:suggestion
25+
dotnet_style_coalesce_expression = true:suggestion
26+
dotnet_style_null_propagation = true:suggestion
27+
dotnet_style_explicit_tuple_names = true:suggestion
28+
# Prefer "var" everywhere
29+
csharp_style_var_for_built_in_types = true:suggestion
30+
csharp_style_var_when_type_is_apparent = true:suggestion
31+
csharp_style_var_elsewhere = true:suggestion
32+
# Prefer method-like constructs to have a expression body
33+
csharp_style_expression_bodied_methods = true:suggestion
34+
csharp_style_expression_bodied_constructors = true:suggestion
35+
csharp_style_expression_bodied_operators = true:suggestion
36+
# Prefer property-like constructs to have an expression-body
37+
csharp_style_expression_bodied_properties = true:suggestion
38+
csharp_style_expression_bodied_indexers = true:suggestion
39+
csharp_style_expression_bodied_accessors = true:suggestion
40+
# Suggest more modern language features when available
41+
csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion
42+
csharp_style_pattern_matching_over_as_with_null_check = true:suggestion
43+
csharp_style_inlined_variable_declaration = true:suggestion
44+
csharp_style_throw_expression = true:suggestion
45+
csharp_style_conditional_delegate_call = true:suggestion
46+
# Newline settings
47+
csharp_new_line_before_open_brace = all
48+
csharp_new_line_before_else = true
49+
csharp_new_line_before_catch = true
50+
csharp_new_line_before_finally = true
51+
csharp_new_line_before_members_in_object_initializers = true
52+
csharp_new_line_before_members_in_anonymous_types = true
653

7-
[*.{csproj,json,yml}]
54+
[*.csproj]
855
indent_size = 2
56+
57+
[*.json]
58+
indent_size = 2
59+
60+
[*.{yaml,yml}]
61+
indent_size = 2

dotnet-framework-sample.sln

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 15
4+
VisualStudioVersion = 15.0.27428.2043
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "serilog", "serilog\serilog.csproj", "{527EBA2E-7F09-4229-9421-B764CB733DB0}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{527EBA2E-7F09-4229-9421-B764CB733DB0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{527EBA2E-7F09-4229-9421-B764CB733DB0}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{527EBA2E-7F09-4229-9421-B764CB733DB0}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{527EBA2E-7F09-4229-9421-B764CB733DB0}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {608A1DEF-C273-462C-8E73-20A3B247E894}
24+
EndGlobalSection
25+
EndGlobal
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
2+
<s:String x:Key="/Default/CodeInspection/Highlighting/AnalysisEnabled/@EntryValue">SOLUTION</s:String>
3+
4+
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateInstanceFields/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;</s:String>
5+
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateStaticFields/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;</s:String>
6+
</wpf:ResourceDictionary>

serilog/App.config

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
5+
</startup>
6+
</configuration>

serilog/Generators/Customer.cs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace Serilog.Generators
2+
{
3+
public class Customer
4+
{
5+
public string FirstName { get; set; }
6+
7+
public string Surname { get; set; }
8+
9+
public string SocialSecurityNumber { get; set; }
10+
}
11+
}
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using Bogus;
2+
3+
namespace Serilog.Generators
4+
{
5+
public class CustomerGenerator
6+
{
7+
private readonly Faker<Customer> faker;
8+
9+
public CustomerGenerator()
10+
{
11+
var randomizer = new Randomizer();
12+
13+
faker = new Faker<Customer>()
14+
.RuleFor(customer => customer.FirstName, faker => faker.Name.FirstName())
15+
.RuleFor(customer => customer.Surname, faker => faker.Name.LastName())
16+
.RuleFor(customer => customer.SocialSecurityNumber, _ => randomizer.Replace("###-##-####"));
17+
}
18+
19+
public Customer Generate() => faker.Generate();
20+
}
21+
}

serilog/Generators/Order.cs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace Serilog.Generators
2+
{
3+
public class Order
4+
{
5+
public int Id { get; set; }
6+
7+
public string Item { get; set; }
8+
9+
public int Quantity { get; set; }
10+
}
11+
}

serilog/Generators/OrderGenerator.cs

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using Bogus;
2+
3+
namespace Serilog.Generators
4+
{
5+
public class OrderGenerator
6+
{
7+
private readonly Faker<Order> faker;
8+
9+
public OrderGenerator()
10+
{
11+
var currentOrderId = 0;
12+
var fruit = new[] { "apple", "banana", "orange", "strawberry", "kiwi" };
13+
14+
faker = new Faker<Order>()
15+
.RuleFor(order => order.Id, _ => currentOrderId++)
16+
.RuleFor(order => order.Item, faker => faker.PickRandom(fruit))
17+
.RuleFor(order => order.Quantity, faker => faker.Random.Number(1, 10));
18+
}
19+
20+
public Order Generate() => faker.Generate();
21+
}
22+
}

serilog/Program.cs

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System.Threading;
2+
using Serilog.Generators;
3+
4+
namespace Serilog
5+
{
6+
class Program
7+
{
8+
static void Main()
9+
{
10+
ILogger logger = new LoggerConfiguration()
11+
.WriteTo.DurableHttp("http://logstash:8080")
12+
.WriteTo.Console()
13+
.CreateLogger()
14+
.ForContext<Program>();
15+
16+
var customerGenerator = new CustomerGenerator();
17+
var orderGenerator = new OrderGenerator();
18+
19+
while (true)
20+
{
21+
var customer = customerGenerator.Generate();
22+
var order = orderGenerator.Generate();
23+
24+
logger.Information("{@customer} placed {@order}", customer, order);
25+
26+
Thread.Sleep(1000);
27+
}
28+
}
29+
}
30+
}

serilog/Properties/AssemblyInfo.cs

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

serilog/packages.config

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="Bogus" version="22.0.8" targetFramework="net461" />
4+
<package id="Serilog" version="2.6.0" targetFramework="net461" />
5+
<package id="Serilog.Sinks.Console" version="3.1.1" targetFramework="net461" />
6+
<package id="Serilog.Sinks.File" version="4.0.0" targetFramework="net461" />
7+
<package id="Serilog.Sinks.Http" version="4.3.0" targetFramework="net461" />
8+
<package id="Serilog.Sinks.PeriodicBatching" version="2.1.1" targetFramework="net461" />
9+
<package id="Serilog.Sinks.RollingFile" version="3.3.0" targetFramework="net461" />
10+
</packages>

serilog/serilog.csproj

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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>{527EBA2E-7F09-4229-9421-B764CB733DB0}</ProjectGuid>
8+
<OutputType>Exe</OutputType>
9+
<RootNamespace>Serilog</RootNamespace>
10+
<AssemblyName>serilog</AssemblyName>
11+
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
12+
<FileAlignment>512</FileAlignment>
13+
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
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="Bogus, Version=22.0.8.0, Culture=neutral, PublicKeyToken=fa1bb3f3f218129a, processorArchitecture=MSIL">
36+
<HintPath>..\packages\Bogus.22.0.8\lib\net40\Bogus.dll</HintPath>
37+
</Reference>
38+
<Reference Include="Serilog, Version=2.0.0.0, Culture=neutral, PublicKeyToken=24c2f752a8e58a10, processorArchitecture=MSIL">
39+
<HintPath>..\packages\Serilog.2.6.0\lib\net46\Serilog.dll</HintPath>
40+
</Reference>
41+
<Reference Include="Serilog.Sinks.Console, Version=3.1.1.0, Culture=neutral, PublicKeyToken=24c2f752a8e58a10, processorArchitecture=MSIL">
42+
<HintPath>..\packages\Serilog.Sinks.Console.3.1.1\lib\net45\Serilog.Sinks.Console.dll</HintPath>
43+
</Reference>
44+
<Reference Include="Serilog.Sinks.File, Version=2.0.0.0, Culture=neutral, PublicKeyToken=24c2f752a8e58a10, processorArchitecture=MSIL">
45+
<HintPath>..\packages\Serilog.Sinks.File.4.0.0\lib\net45\Serilog.Sinks.File.dll</HintPath>
46+
</Reference>
47+
<Reference Include="Serilog.Sinks.Http, Version=4.3.0.0, Culture=neutral, PublicKeyToken=24c2f752a8e58a10, processorArchitecture=MSIL">
48+
<HintPath>..\packages\Serilog.Sinks.Http.4.3.0\lib\net45\Serilog.Sinks.Http.dll</HintPath>
49+
</Reference>
50+
<Reference Include="Serilog.Sinks.PeriodicBatching, Version=2.0.0.0, Culture=neutral, PublicKeyToken=24c2f752a8e58a10, processorArchitecture=MSIL">
51+
<HintPath>..\packages\Serilog.Sinks.PeriodicBatching.2.1.1\lib\net45\Serilog.Sinks.PeriodicBatching.dll</HintPath>
52+
</Reference>
53+
<Reference Include="Serilog.Sinks.RollingFile, Version=2.0.0.0, Culture=neutral, PublicKeyToken=24c2f752a8e58a10, processorArchitecture=MSIL">
54+
<HintPath>..\packages\Serilog.Sinks.RollingFile.3.3.0\lib\net45\Serilog.Sinks.RollingFile.dll</HintPath>
55+
</Reference>
56+
<Reference Include="System" />
57+
<Reference Include="System.Core" />
58+
<Reference Include="System.Xml.Linq" />
59+
<Reference Include="System.Data.DataSetExtensions" />
60+
<Reference Include="Microsoft.CSharp" />
61+
<Reference Include="System.Data" />
62+
<Reference Include="System.Net.Http" />
63+
<Reference Include="System.Xml" />
64+
</ItemGroup>
65+
<ItemGroup>
66+
<Compile Include="Generators\Customer.cs" />
67+
<Compile Include="Generators\CustomerGenerator.cs" />
68+
<Compile Include="Generators\Order.cs" />
69+
<Compile Include="Generators\OrderGenerator.cs" />
70+
<Compile Include="Program.cs" />
71+
<Compile Include="Properties\AssemblyInfo.cs" />
72+
</ItemGroup>
73+
<ItemGroup>
74+
<None Include="App.config" />
75+
<None Include="packages.config" />
76+
</ItemGroup>
77+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
78+
</Project>

0 commit comments

Comments
 (0)