Skip to content

Commit

Permalink
Feature/161 subsecond decimals (#172)
Browse files Browse the repository at this point in the history
* 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 <toryberra@gmail.com>
  • Loading branch information
EEParker and LordZeroHour committed Mar 26, 2024
1 parent dcacbbc commit 87e782c
Show file tree
Hide file tree
Showing 26 changed files with 651 additions and 109 deletions.
181 changes: 181 additions & 0 deletions .editorconfig
@@ -0,0 +1,181 @@
# To learn more about .editorconfig see https://aka.ms/editorconfigdocs
###############################
# Core EditorConfig Options #
###############################
# All files
[*]
indent_style = space
trim_trailing_whitespace = true

[Caddyfile]
indent_size = tab

# XML project files
[*.{csproj,vbproj,vcxproj,vcxproj.filters,proj,projitems,shproj,dcproj}]
indent_size = 2

# XML config files
[*.{props,targets,ruleset,config,nuspec,resx,vsixmanifest,vsct}]
indent_size = 2

# JSON config files
[*.{json,jsonc}]
indent_size = 2
insert_final_newline = true

# YAML config files
[*.{yml,yaml}]
indent_size = 2
insert_final_newline = true

# Code files
[*.{cs,csx,vb,vbx}]
indent_size = 4
insert_final_newline = true
charset = utf-8-bom

# Markdown
[*.{md, mmd}]
indent_size = 4
insert_final_newline = true
trim_trailing_whitespace = false

###############################
# .NET Coding Conventions #
###############################
[*.{cs,vb}]
# Instance fields are camelCase and start with _
dotnet_naming_rule.instance_fields_should_be_camel_case.severity = suggestion
dotnet_naming_rule.instance_fields_should_be_camel_case.symbols = instance_fields
dotnet_naming_rule.instance_fields_should_be_camel_case.style = instance_field_style
dotnet_naming_symbols.instance_fields.applicable_kinds = field
dotnet_naming_style.instance_field_style.capitalization = camel_case
dotnet_naming_style.instance_field_style.required_prefix = _
# Organize usings
dotnet_sort_system_directives_first = true
# this. preferences
dotnet_style_qualification_for_field = false:silent
dotnet_style_qualification_for_property = false:silent
dotnet_style_qualification_for_method = false:silent
dotnet_style_qualification_for_event = false:silent
# Language keywords vs BCL types preferences
dotnet_style_predefined_type_for_locals_parameters_members = true:silent
dotnet_style_predefined_type_for_member_access = true:silent
# Parentheses preferences
dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:silent
dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:silent
dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:silent
dotnet_style_parentheses_in_other_operators = never_if_unnecessary:silent
# Modifier preferences
dotnet_style_require_accessibility_modifiers = for_non_interface_members:silent
dotnet_style_readonly_field = true:suggestion
# Expression-level preferences
dotnet_style_object_initializer = true:suggestion
dotnet_style_collection_initializer = true:suggestion
dotnet_style_explicit_tuple_names = true:suggestion
dotnet_style_null_propagation = true:suggestion
dotnet_style_coalesce_expression = true:suggestion
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:silent
dotnet_style_prefer_inferred_tuple_names = true:suggestion
dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion
dotnet_style_prefer_auto_properties = true:silent
dotnet_style_prefer_conditional_expression_over_assignment = true:silent
dotnet_style_prefer_conditional_expression_over_return = true:silent
###############################
# Naming Conventions #
###############################
# Style Definitions
dotnet_naming_style.pascal_case_style.capitalization = pascal_case
# Use PascalCase for constant fields
dotnet_naming_rule.constant_fields_should_be_pascal_case.severity = suggestion
dotnet_naming_rule.constant_fields_should_be_pascal_case.symbols = constant_fields
dotnet_naming_rule.constant_fields_should_be_pascal_case.style = pascal_case_style
dotnet_naming_symbols.constant_fields.applicable_kinds = field
dotnet_naming_symbols.constant_fields.applicable_accessibilities = *
dotnet_naming_symbols.constant_fields.required_modifiers = const
dotnet_style_prefer_simplified_boolean_expressions = true:suggestion
dotnet_style_operator_placement_when_wrapping = beginning_of_line
tab_width = 4
end_of_line = crlf
dotnet_style_prefer_compound_assignment = true:suggestion
dotnet_style_prefer_simplified_interpolation = true:suggestion
dotnet_style_namespace_match_folder = true:suggestion
dotnet_style_prefer_collection_expression = true:suggestion
###############################
# C# Coding Conventions #
###############################
[*.cs]
# var preferences
csharp_style_var_for_built_in_types = true:silent
csharp_style_var_when_type_is_apparent = true:silent
csharp_style_var_elsewhere = true:silent
# Expression-bodied members
csharp_style_expression_bodied_methods = false:silent
csharp_style_expression_bodied_constructors = false:silent
csharp_style_expression_bodied_operators = false:silent
csharp_style_expression_bodied_properties = true:silent
csharp_style_expression_bodied_indexers = true:silent
csharp_style_expression_bodied_accessors = true:silent
# Pattern matching preferences
csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion
csharp_style_pattern_matching_over_as_with_null_check = true:suggestion
# Null-checking preferences
csharp_style_throw_expression = true:suggestion
csharp_style_conditional_delegate_call = true:suggestion
# Modifier preferences
csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async:suggestion
# Expression-level preferences
csharp_prefer_braces = true:silent
csharp_style_deconstructed_variable_declaration = true:suggestion
csharp_prefer_simple_default_expression = true:suggestion
csharp_style_pattern_local_over_anonymous_function = true:suggestion
csharp_style_inlined_variable_declaration = true:suggestion
###############################
# C# Formatting Rules #
###############################
# New line preferences
csharp_new_line_before_open_brace = all
csharp_new_line_before_else = true
csharp_new_line_before_catch = true
csharp_new_line_before_finally = true
csharp_new_line_before_members_in_object_initializers = true
csharp_new_line_before_members_in_anonymous_types = true
csharp_new_line_between_query_expression_clauses = true
# Indentation preferences
csharp_indent_case_contents = true
csharp_indent_switch_labels = true
csharp_indent_labels = flush_left
# Space preferences
csharp_space_after_cast = false
csharp_space_after_keywords_in_control_flow_statements = true
csharp_space_between_method_call_parameter_list_parentheses = false
csharp_space_between_method_declaration_parameter_list_parentheses = false
csharp_space_between_parentheses = false
csharp_space_before_colon_in_inheritance_clause = true
csharp_space_after_colon_in_inheritance_clause = true
csharp_space_around_binary_operators = before_and_after
csharp_space_between_method_declaration_empty_parameter_list_parentheses = false
csharp_space_between_method_call_name_and_opening_parenthesis = false
csharp_space_between_method_call_empty_parameter_list_parentheses = false
# Wrapping preferences
csharp_preserve_single_line_statements = true
csharp_preserve_single_line_blocks = true
csharp_using_directive_placement = outside_namespace:suggestion
csharp_prefer_simple_using_statement = true:suggestion
csharp_style_namespace_declarations = file_scoped:suggestion
csharp_style_expression_bodied_lambdas = true:silent
csharp_style_expression_bodied_local_functions = true:silent
csharp_style_prefer_null_check_over_type_check = true:suggestion
csharp_style_prefer_method_group_conversion = true:silent
csharp_style_prefer_top_level_statements = true:silent
csharp_style_prefer_local_over_anonymous_function = true:suggestion
csharp_style_prefer_index_operator = true:suggestion
csharp_style_prefer_range_operator = true:suggestion
csharp_style_implicit_object_creation_when_type_is_apparent = true:suggestion
csharp_style_prefer_primary_constructors = true:suggestion
###############################
# VB Coding Conventions #
###############################
[*.vb]
# Modifier preferences
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
2 changes: 1 addition & 1 deletion CHANGES.md
Expand Up @@ -69,7 +69,7 @@
- Event Collector fluent interface changed to `.WriteTo.EventCollector`
- Event Collector Sink targeting core
- TCP/UDP Sinks targeting 4.5 *ONLY*
- Updated Event Collector HTTP Client to add URI endpoint to host: "services/collector" if not included.
- Updated Event Collector HTTP Client to add URI endpoint to host: "services/collector/event" if not included.
- Event Collector changed to use epoch time [#15](https://github.com/serilog/serilog-sinks-splunk/pull/15)

## 1.8
Expand Down
32 changes: 32 additions & 0 deletions Create-DockerfileSolutionRestore.ps1
@@ -0,0 +1,32 @@
param (
[string]$solution = "serilog-sinks-splunk.sln"
)

$outfile = "DockerfileSolutionRestore.txt"

# This script creates the $outfile file, with Dockerfile commands to restore all the packages for the solution,
# so you can insert them (by hand) into Dockerfiles right before the "COPY . ." line
# to increase build speed by optimizing the use of docker build images cache.

# This script is only needed when adding or removing projects from the solution.

Write-Output "" > $outfile
Add-Content -Path $outfile "# Create this ""restore-solution"" section by running ./Create-DockerfileSolutionRestore.ps1, to optimize build cache reuse"
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
Add-Content -Path $outfile "COPY [""docker-compose.dcproj"", ""./""]"
Add-Content -Path $outfile "COPY [""$solution"", ""./""]"
Add-Content -Path $outfile "RUN dotnet restore ""$solution"""
Add-Content -Path $outfile ""


Add-Content -Path $outfile "# Docker Compose Paths"

Get-ChildItem -Path "./" -Recurse -Filter "Dockerfile" |
Resolve-Path -Relative |
ForEach-Object { $_.Replace("\", "/") }
Sort-Object |
ForEach-Object {" ""$_"""} |
Out-File -FilePath $outfile -Append


Get-Content $outfile
10 changes: 0 additions & 10 deletions Dockerfile

This file was deleted.

13 changes: 13 additions & 0 deletions DockerfileSolutionRestore.txt
@@ -0,0 +1,13 @@

# Create this "restore-solution" section by running ./Create-DockerfileSolutionRestore.ps1, to optimize build cache reuse
COPY ["sample/Sample/Sample.csproj", "sample/Sample/"]
COPY ["src/Serilog.Sinks.Splunk/Serilog.Sinks.Splunk.csproj", "src/Serilog.Sinks.Splunk/"]
COPY ["src/Serilog.Sinks.TCP/Serilog.Sinks.Splunk.TCP.csproj", "src/Serilog.Sinks.TCP/"]
COPY ["src/Serilog.Sinks.UDP/Serilog.Sinks.Splunk.UDP.csproj", "src/Serilog.Sinks.UDP/"]
COPY ["test/Serilog.Sinks.Splunk.Tests/Serilog.Sinks.Splunk.Tests.csproj", "test/Serilog.Sinks.Splunk.Tests/"]
COPY ["docker-compose.dcproj", "./"]
COPY ["nuget.config", "./"]
COPY ["serilog-sinks-splunk.sln", "./"]
RUN dotnet restore "serilog-sinks-splunk.sln"

# Docker Compose Paths
17 changes: 17 additions & 0 deletions docker-compose.dcproj
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" Sdk="Microsoft.Docker.Sdk">
<PropertyGroup Label="Globals">
<ProjectVersion>2.1</ProjectVersion>
<DockerTargetOS>Linux</DockerTargetOS>
<ProjectGuid>1b9defa3-d600-45fa-93a5-79006076fb5c</ProjectGuid>
<DockerComposeProjectName>serilogsinkssplunk</DockerComposeProjectName>
</PropertyGroup>
<ItemGroup>
<None Include="deploy/**/*" />
<None Include="docker-compose.override.yml">
<DependentUpon>docker-compose.yml</DependentUpon>
</None>
<None Include="docker-compose.yml" />
<None Include=".dockerignore" />
</ItemGroup>
</Project>
13 changes: 13 additions & 0 deletions docker-compose.override.yml
@@ -0,0 +1,13 @@
version: '3.4'
#https://learn.microsoft.com/en-us/visualstudio/containers/docker-compose-properties

services:
splunk:
ports:
- 8000:8000
- 8088:8088
- 8089:8089

sampleconsoleapp:
ports:
- 8080:8080
33 changes: 15 additions & 18 deletions docker-compose.yml
@@ -1,25 +1,22 @@
version: '3'
services:
splunk:
build: ./sample/splunk
image: serilog-splunk
container_name: splunk
build:
context: .
dockerfile: sample/splunk/Dockerfile
volumes:
- "./sample/splunk/default.yml:/tmp/defaults/default.yml"
environment:
SPLUNK_START_ARGS: --accept-license --answer-yes --seed-passwd changeme
SPLUNK_ENABLE_LISTEN: 9997
SPLUNK_PASSWORD: changemeplease!
ports:
- 8000:8000
- 8088:8088
- 8089:8089
networks:
splunkbase_docker:
SPLUNK_START_ARGS: --accept-license --answer-yes --seed-passwd changeme
SPLUNK_ENABLE_LISTEN: 9997
SPLUNK_PASSWORD: changemeplease!
SPLUNK_HEC_TOKEN: 00112233-4455-6677-8899-AABBCCDDEEFF

sampleconsoleapp:
container_name: sample
depends_on:
- "splunk"
build: .
image: serilog-console-sample
networks:
splunkbase_docker:
networks:
splunkbase_docker:

build:
context: .
dockerfile: sample/Sample/Dockerfile
31 changes: 31 additions & 0 deletions sample/Sample/Dockerfile
@@ -0,0 +1,31 @@
#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.
FROM mcr.microsoft.com/dotnet/runtime:8.0 AS base
WORKDIR /app
EXPOSE 8080

FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src

# Create this "restore-solution" section by running ./Create-DockerfileSolutionRestore.ps1, to optimize build cache reuse
COPY ["sample/Sample/Sample.csproj", "sample/Sample/"]
COPY ["src/Serilog.Sinks.Splunk/Serilog.Sinks.Splunk.csproj", "src/Serilog.Sinks.Splunk/"]
COPY ["src/Serilog.Sinks.TCP/Serilog.Sinks.Splunk.TCP.csproj", "src/Serilog.Sinks.TCP/"]
COPY ["src/Serilog.Sinks.UDP/Serilog.Sinks.Splunk.UDP.csproj", "src/Serilog.Sinks.UDP/"]
COPY ["test/Serilog.Sinks.Splunk.Tests/Serilog.Sinks.Splunk.Tests.csproj", "test/Serilog.Sinks.Splunk.Tests/"]
COPY ["docker-compose.dcproj", "./"]
COPY ["serilog-sinks-splunk.sln", "./"]
RUN dotnet restore "serilog-sinks-splunk.sln"

COPY . .
WORKDIR "/src/sample/Sample/"
RUN dotnet build "./Sample.csproj" -c $BUILD_CONFIGURATION -o /app/build

FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "./Sample.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Sample.dll"]

0 comments on commit 87e782c

Please sign in to comment.