Skip to content

Commit 87e782c

Browse files
Feature/161 subsecond decimals (#172)
* Fixes #161 add subsecond decimal configuration * Fixes #167 Add a flag for RenderedMessage * Update SubSecondPrecision to use an enum. Based on 3,6,9 decimals, see https://docs.splunk.com/Documentation/Splunk/9.2.0/SearchReference/Commontimeformatvariables * Add unit tests and update documentation * Invert renderMessage check * Update sample docker-compose project - add new tests - add a docker-compose vscode project - allow subsecond precision. * Add comment for configuring splunk * Fix formatting for nanoseconds * Enable all tests in sample app --------- Co-authored-by: Victorio Berra <[email protected]>
1 parent dcacbbc commit 87e782c

26 files changed

+651
-109
lines changed

.editorconfig

Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
# To learn more about .editorconfig see https://aka.ms/editorconfigdocs
2+
###############################
3+
# Core EditorConfig Options #
4+
###############################
5+
# All files
6+
[*]
7+
indent_style = space
8+
trim_trailing_whitespace = true
9+
10+
[Caddyfile]
11+
indent_size = tab
12+
13+
# XML project files
14+
[*.{csproj,vbproj,vcxproj,vcxproj.filters,proj,projitems,shproj,dcproj}]
15+
indent_size = 2
16+
17+
# XML config files
18+
[*.{props,targets,ruleset,config,nuspec,resx,vsixmanifest,vsct}]
19+
indent_size = 2
20+
21+
# JSON config files
22+
[*.{json,jsonc}]
23+
indent_size = 2
24+
insert_final_newline = true
25+
26+
# YAML config files
27+
[*.{yml,yaml}]
28+
indent_size = 2
29+
insert_final_newline = true
30+
31+
# Code files
32+
[*.{cs,csx,vb,vbx}]
33+
indent_size = 4
34+
insert_final_newline = true
35+
charset = utf-8-bom
36+
37+
# Markdown
38+
[*.{md, mmd}]
39+
indent_size = 4
40+
insert_final_newline = true
41+
trim_trailing_whitespace = false
42+
43+
###############################
44+
# .NET Coding Conventions #
45+
###############################
46+
[*.{cs,vb}]
47+
# Instance fields are camelCase and start with _
48+
dotnet_naming_rule.instance_fields_should_be_camel_case.severity = suggestion
49+
dotnet_naming_rule.instance_fields_should_be_camel_case.symbols = instance_fields
50+
dotnet_naming_rule.instance_fields_should_be_camel_case.style = instance_field_style
51+
dotnet_naming_symbols.instance_fields.applicable_kinds = field
52+
dotnet_naming_style.instance_field_style.capitalization = camel_case
53+
dotnet_naming_style.instance_field_style.required_prefix = _
54+
# Organize usings
55+
dotnet_sort_system_directives_first = true
56+
# this. preferences
57+
dotnet_style_qualification_for_field = false:silent
58+
dotnet_style_qualification_for_property = false:silent
59+
dotnet_style_qualification_for_method = false:silent
60+
dotnet_style_qualification_for_event = false:silent
61+
# Language keywords vs BCL types preferences
62+
dotnet_style_predefined_type_for_locals_parameters_members = true:silent
63+
dotnet_style_predefined_type_for_member_access = true:silent
64+
# Parentheses preferences
65+
dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:silent
66+
dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:silent
67+
dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:silent
68+
dotnet_style_parentheses_in_other_operators = never_if_unnecessary:silent
69+
# Modifier preferences
70+
dotnet_style_require_accessibility_modifiers = for_non_interface_members:silent
71+
dotnet_style_readonly_field = true:suggestion
72+
# Expression-level preferences
73+
dotnet_style_object_initializer = true:suggestion
74+
dotnet_style_collection_initializer = true:suggestion
75+
dotnet_style_explicit_tuple_names = true:suggestion
76+
dotnet_style_null_propagation = true:suggestion
77+
dotnet_style_coalesce_expression = true:suggestion
78+
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:silent
79+
dotnet_style_prefer_inferred_tuple_names = true:suggestion
80+
dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion
81+
dotnet_style_prefer_auto_properties = true:silent
82+
dotnet_style_prefer_conditional_expression_over_assignment = true:silent
83+
dotnet_style_prefer_conditional_expression_over_return = true:silent
84+
###############################
85+
# Naming Conventions #
86+
###############################
87+
# Style Definitions
88+
dotnet_naming_style.pascal_case_style.capitalization = pascal_case
89+
# Use PascalCase for constant fields
90+
dotnet_naming_rule.constant_fields_should_be_pascal_case.severity = suggestion
91+
dotnet_naming_rule.constant_fields_should_be_pascal_case.symbols = constant_fields
92+
dotnet_naming_rule.constant_fields_should_be_pascal_case.style = pascal_case_style
93+
dotnet_naming_symbols.constant_fields.applicable_kinds = field
94+
dotnet_naming_symbols.constant_fields.applicable_accessibilities = *
95+
dotnet_naming_symbols.constant_fields.required_modifiers = const
96+
dotnet_style_prefer_simplified_boolean_expressions = true:suggestion
97+
dotnet_style_operator_placement_when_wrapping = beginning_of_line
98+
tab_width = 4
99+
end_of_line = crlf
100+
dotnet_style_prefer_compound_assignment = true:suggestion
101+
dotnet_style_prefer_simplified_interpolation = true:suggestion
102+
dotnet_style_namespace_match_folder = true:suggestion
103+
dotnet_style_prefer_collection_expression = true:suggestion
104+
###############################
105+
# C# Coding Conventions #
106+
###############################
107+
[*.cs]
108+
# var preferences
109+
csharp_style_var_for_built_in_types = true:silent
110+
csharp_style_var_when_type_is_apparent = true:silent
111+
csharp_style_var_elsewhere = true:silent
112+
# Expression-bodied members
113+
csharp_style_expression_bodied_methods = false:silent
114+
csharp_style_expression_bodied_constructors = false:silent
115+
csharp_style_expression_bodied_operators = false:silent
116+
csharp_style_expression_bodied_properties = true:silent
117+
csharp_style_expression_bodied_indexers = true:silent
118+
csharp_style_expression_bodied_accessors = true:silent
119+
# Pattern matching preferences
120+
csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion
121+
csharp_style_pattern_matching_over_as_with_null_check = true:suggestion
122+
# Null-checking preferences
123+
csharp_style_throw_expression = true:suggestion
124+
csharp_style_conditional_delegate_call = true:suggestion
125+
# Modifier preferences
126+
csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async:suggestion
127+
# Expression-level preferences
128+
csharp_prefer_braces = true:silent
129+
csharp_style_deconstructed_variable_declaration = true:suggestion
130+
csharp_prefer_simple_default_expression = true:suggestion
131+
csharp_style_pattern_local_over_anonymous_function = true:suggestion
132+
csharp_style_inlined_variable_declaration = true:suggestion
133+
###############################
134+
# C# Formatting Rules #
135+
###############################
136+
# New line preferences
137+
csharp_new_line_before_open_brace = all
138+
csharp_new_line_before_else = true
139+
csharp_new_line_before_catch = true
140+
csharp_new_line_before_finally = true
141+
csharp_new_line_before_members_in_object_initializers = true
142+
csharp_new_line_before_members_in_anonymous_types = true
143+
csharp_new_line_between_query_expression_clauses = true
144+
# Indentation preferences
145+
csharp_indent_case_contents = true
146+
csharp_indent_switch_labels = true
147+
csharp_indent_labels = flush_left
148+
# Space preferences
149+
csharp_space_after_cast = false
150+
csharp_space_after_keywords_in_control_flow_statements = true
151+
csharp_space_between_method_call_parameter_list_parentheses = false
152+
csharp_space_between_method_declaration_parameter_list_parentheses = false
153+
csharp_space_between_parentheses = false
154+
csharp_space_before_colon_in_inheritance_clause = true
155+
csharp_space_after_colon_in_inheritance_clause = true
156+
csharp_space_around_binary_operators = before_and_after
157+
csharp_space_between_method_declaration_empty_parameter_list_parentheses = false
158+
csharp_space_between_method_call_name_and_opening_parenthesis = false
159+
csharp_space_between_method_call_empty_parameter_list_parentheses = false
160+
# Wrapping preferences
161+
csharp_preserve_single_line_statements = true
162+
csharp_preserve_single_line_blocks = true
163+
csharp_using_directive_placement = outside_namespace:suggestion
164+
csharp_prefer_simple_using_statement = true:suggestion
165+
csharp_style_namespace_declarations = file_scoped:suggestion
166+
csharp_style_expression_bodied_lambdas = true:silent
167+
csharp_style_expression_bodied_local_functions = true:silent
168+
csharp_style_prefer_null_check_over_type_check = true:suggestion
169+
csharp_style_prefer_method_group_conversion = true:silent
170+
csharp_style_prefer_top_level_statements = true:silent
171+
csharp_style_prefer_local_over_anonymous_function = true:suggestion
172+
csharp_style_prefer_index_operator = true:suggestion
173+
csharp_style_prefer_range_operator = true:suggestion
174+
csharp_style_implicit_object_creation_when_type_is_apparent = true:suggestion
175+
csharp_style_prefer_primary_constructors = true:suggestion
176+
###############################
177+
# VB Coding Conventions #
178+
###############################
179+
[*.vb]
180+
# Modifier preferences
181+
visual_basic_preferred_modifier_order = Partial,Default,Private,Protected,Public,Friend,NotOverridable,Overridable,MustOverride,Overloads,Overrides,MustInherit,NotInheritable,Static,Shared,Shadows,ReadOnly,WriteOnly,Dim,Const,WithEvents,Widening,Narrowing,Custom,Async:suggestion

CHANGES.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
- Event Collector fluent interface changed to `.WriteTo.EventCollector`
7070
- Event Collector Sink targeting core
7171
- TCP/UDP Sinks targeting 4.5 *ONLY*
72-
- Updated Event Collector HTTP Client to add URI endpoint to host: "services/collector" if not included.
72+
- Updated Event Collector HTTP Client to add URI endpoint to host: "services/collector/event" if not included.
7373
- Event Collector changed to use epoch time [#15](https://github.com/serilog/serilog-sinks-splunk/pull/15)
7474

7575
## 1.8

Create-DockerfileSolutionRestore.ps1

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
param (
2+
[string]$solution = "serilog-sinks-splunk.sln"
3+
)
4+
5+
$outfile = "DockerfileSolutionRestore.txt"
6+
7+
# This script creates the $outfile file, with Dockerfile commands to restore all the packages for the solution,
8+
# so you can insert them (by hand) into Dockerfiles right before the "COPY . ." line
9+
# to increase build speed by optimizing the use of docker build images cache.
10+
11+
# This script is only needed when adding or removing projects from the solution.
12+
13+
Write-Output "" > $outfile
14+
Add-Content -Path $outfile "# Create this ""restore-solution"" section by running ./Create-DockerfileSolutionRestore.ps1, to optimize build cache reuse"
15+
Select-String -Path $solution -Pattern ', "(.*?\.csproj)"' | ForEach-Object { $_.Matches.Groups[1].Value.Replace("\", "/") } | Sort-Object | ForEach-Object {"COPY [""$_"", """ + $_.Substring(0, $_.LastIndexOf("/") + 1) + """]"} | Out-File -FilePath $outfile -Append
16+
Add-Content -Path $outfile "COPY [""docker-compose.dcproj"", ""./""]"
17+
Add-Content -Path $outfile "COPY [""$solution"", ""./""]"
18+
Add-Content -Path $outfile "RUN dotnet restore ""$solution"""
19+
Add-Content -Path $outfile ""
20+
21+
22+
Add-Content -Path $outfile "# Docker Compose Paths"
23+
24+
Get-ChildItem -Path "./" -Recurse -Filter "Dockerfile" |
25+
Resolve-Path -Relative |
26+
ForEach-Object { $_.Replace("\", "/") }
27+
Sort-Object |
28+
ForEach-Object {" ""$_"""} |
29+
Out-File -FilePath $outfile -Append
30+
31+
32+
Get-Content $outfile

Dockerfile

Lines changed: 0 additions & 10 deletions
This file was deleted.

DockerfileSolutionRestore.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
# Create this "restore-solution" section by running ./Create-DockerfileSolutionRestore.ps1, to optimize build cache reuse
3+
COPY ["sample/Sample/Sample.csproj", "sample/Sample/"]
4+
COPY ["src/Serilog.Sinks.Splunk/Serilog.Sinks.Splunk.csproj", "src/Serilog.Sinks.Splunk/"]
5+
COPY ["src/Serilog.Sinks.TCP/Serilog.Sinks.Splunk.TCP.csproj", "src/Serilog.Sinks.TCP/"]
6+
COPY ["src/Serilog.Sinks.UDP/Serilog.Sinks.Splunk.UDP.csproj", "src/Serilog.Sinks.UDP/"]
7+
COPY ["test/Serilog.Sinks.Splunk.Tests/Serilog.Sinks.Splunk.Tests.csproj", "test/Serilog.Sinks.Splunk.Tests/"]
8+
COPY ["docker-compose.dcproj", "./"]
9+
COPY ["nuget.config", "./"]
10+
COPY ["serilog-sinks-splunk.sln", "./"]
11+
RUN dotnet restore "serilog-sinks-splunk.sln"
12+
13+
# Docker Compose Paths

docker-compose.dcproj

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" Sdk="Microsoft.Docker.Sdk">
3+
<PropertyGroup Label="Globals">
4+
<ProjectVersion>2.1</ProjectVersion>
5+
<DockerTargetOS>Linux</DockerTargetOS>
6+
<ProjectGuid>1b9defa3-d600-45fa-93a5-79006076fb5c</ProjectGuid>
7+
<DockerComposeProjectName>serilogsinkssplunk</DockerComposeProjectName>
8+
</PropertyGroup>
9+
<ItemGroup>
10+
<None Include="deploy/**/*" />
11+
<None Include="docker-compose.override.yml">
12+
<DependentUpon>docker-compose.yml</DependentUpon>
13+
</None>
14+
<None Include="docker-compose.yml" />
15+
<None Include=".dockerignore" />
16+
</ItemGroup>
17+
</Project>

docker-compose.override.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
version: '3.4'
2+
#https://learn.microsoft.com/en-us/visualstudio/containers/docker-compose-properties
3+
4+
services:
5+
splunk:
6+
ports:
7+
- 8000:8000
8+
- 8088:8088
9+
- 8089:8089
10+
11+
sampleconsoleapp:
12+
ports:
13+
- 8080:8080

docker-compose.yml

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,22 @@
11
version: '3'
22
services:
33
splunk:
4-
build: ./sample/splunk
5-
image: serilog-splunk
4+
container_name: splunk
5+
build:
6+
context: .
7+
dockerfile: sample/splunk/Dockerfile
8+
volumes:
9+
- "./sample/splunk/default.yml:/tmp/defaults/default.yml"
610
environment:
7-
SPLUNK_START_ARGS: --accept-license --answer-yes --seed-passwd changeme
8-
SPLUNK_ENABLE_LISTEN: 9997
9-
SPLUNK_PASSWORD: changemeplease!
10-
ports:
11-
- 8000:8000
12-
- 8088:8088
13-
- 8089:8089
14-
networks:
15-
splunkbase_docker:
11+
SPLUNK_START_ARGS: --accept-license --answer-yes --seed-passwd changeme
12+
SPLUNK_ENABLE_LISTEN: 9997
13+
SPLUNK_PASSWORD: changemeplease!
14+
SPLUNK_HEC_TOKEN: 00112233-4455-6677-8899-AABBCCDDEEFF
15+
1616
sampleconsoleapp:
17+
container_name: sample
1718
depends_on:
1819
- "splunk"
19-
build: .
20-
image: serilog-console-sample
21-
networks:
22-
splunkbase_docker:
23-
networks:
24-
splunkbase_docker:
25-
20+
build:
21+
context: .
22+
dockerfile: sample/Sample/Dockerfile

sample/Sample/Dockerfile

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging.
2+
FROM mcr.microsoft.com/dotnet/runtime:8.0 AS base
3+
WORKDIR /app
4+
EXPOSE 8080
5+
6+
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
7+
ARG BUILD_CONFIGURATION=Release
8+
WORKDIR /src
9+
10+
# Create this "restore-solution" section by running ./Create-DockerfileSolutionRestore.ps1, to optimize build cache reuse
11+
COPY ["sample/Sample/Sample.csproj", "sample/Sample/"]
12+
COPY ["src/Serilog.Sinks.Splunk/Serilog.Sinks.Splunk.csproj", "src/Serilog.Sinks.Splunk/"]
13+
COPY ["src/Serilog.Sinks.TCP/Serilog.Sinks.Splunk.TCP.csproj", "src/Serilog.Sinks.TCP/"]
14+
COPY ["src/Serilog.Sinks.UDP/Serilog.Sinks.Splunk.UDP.csproj", "src/Serilog.Sinks.UDP/"]
15+
COPY ["test/Serilog.Sinks.Splunk.Tests/Serilog.Sinks.Splunk.Tests.csproj", "test/Serilog.Sinks.Splunk.Tests/"]
16+
COPY ["docker-compose.dcproj", "./"]
17+
COPY ["serilog-sinks-splunk.sln", "./"]
18+
RUN dotnet restore "serilog-sinks-splunk.sln"
19+
20+
COPY . .
21+
WORKDIR "/src/sample/Sample/"
22+
RUN dotnet build "./Sample.csproj" -c $BUILD_CONFIGURATION -o /app/build
23+
24+
FROM build AS publish
25+
ARG BUILD_CONFIGURATION=Release
26+
RUN dotnet publish "./Sample.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
27+
28+
FROM base AS final
29+
WORKDIR /app
30+
COPY --from=publish /app/publish .
31+
ENTRYPOINT ["dotnet", "Sample.dll"]

0 commit comments

Comments
 (0)