diff --git a/README.md b/README.md
index 358d2f3..c8152cb 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,5 @@
# CAF Logging
-This project configures Logback and Log4j2 to meet the CAF Logging Standard.
+This project configures Logback, Log4j2 and Serilog (see [Serilog](caf-logging-serilog/README.md) section) to meet the CAF Logging Standard.
- The log level is controllable via an environment variable.
- The `CAF_LOG_LEVEL` environment variable can be used to configure the required volume of logging.
diff --git a/caf-logging-serilog/.gitignore b/caf-logging-serilog/.gitignore
new file mode 100644
index 0000000..8a30d25
--- /dev/null
+++ b/caf-logging-serilog/.gitignore
@@ -0,0 +1,398 @@
+## Ignore Visual Studio temporary files, build results, and
+## files generated by popular Visual Studio add-ons.
+##
+## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore
+
+# User-specific files
+*.rsuser
+*.suo
+*.user
+*.userosscache
+*.sln.docstates
+
+# User-specific files (MonoDevelop/Xamarin Studio)
+*.userprefs
+
+# Mono auto generated files
+mono_crash.*
+
+# Build results
+[Dd]ebug/
+[Dd]ebugPublic/
+[Rr]elease/
+[Rr]eleases/
+x64/
+x86/
+[Ww][Ii][Nn]32/
+[Aa][Rr][Mm]/
+[Aa][Rr][Mm]64/
+bld/
+[Bb]in/
+[Oo]bj/
+[Ll]og/
+[Ll]ogs/
+
+# Visual Studio 2015/2017 cache/options directory
+.vs/
+# Uncomment if you have tasks that create the project's static files in wwwroot
+#wwwroot/
+
+# Visual Studio 2017 auto generated files
+Generated\ Files/
+
+# MSTest test Results
+[Tt]est[Rr]esult*/
+[Bb]uild[Ll]og.*
+
+# NUnit
+*.VisualState.xml
+TestResult.xml
+nunit-*.xml
+
+# Build Results of an ATL Project
+[Dd]ebugPS/
+[Rr]eleasePS/
+dlldata.c
+
+# Benchmark Results
+BenchmarkDotNet.Artifacts/
+
+# .NET Core
+project.lock.json
+project.fragment.lock.json
+artifacts/
+
+# ASP.NET Scaffolding
+ScaffoldingReadMe.txt
+
+# StyleCop
+StyleCopReport.xml
+
+# Files built by Visual Studio
+*_i.c
+*_p.c
+*_h.h
+*.ilk
+*.meta
+*.obj
+*.iobj
+*.pch
+*.pdb
+*.ipdb
+*.pgc
+*.pgd
+*.rsp
+*.sbr
+*.tlb
+*.tli
+*.tlh
+*.tmp
+*.tmp_proj
+*_wpftmp.csproj
+*.log
+*.tlog
+*.vspscc
+*.vssscc
+.builds
+*.pidb
+*.svclog
+*.scc
+
+# Chutzpah Test files
+_Chutzpah*
+
+# Visual C++ cache files
+ipch/
+*.aps
+*.ncb
+*.opendb
+*.opensdf
+*.sdf
+*.cachefile
+*.VC.db
+*.VC.VC.opendb
+
+# Visual Studio profiler
+*.psess
+*.vsp
+*.vspx
+*.sap
+
+# Visual Studio Trace Files
+*.e2e
+
+# TFS 2012 Local Workspace
+$tf/
+
+# Guidance Automation Toolkit
+*.gpState
+
+# ReSharper is a .NET coding add-in
+_ReSharper*/
+*.[Rr]e[Ss]harper
+*.DotSettings.user
+
+# TeamCity is a build add-in
+_TeamCity*
+
+# DotCover is a Code Coverage Tool
+*.dotCover
+
+# AxoCover is a Code Coverage Tool
+.axoCover/*
+!.axoCover/settings.json
+
+# Coverlet is a free, cross platform Code Coverage Tool
+coverage*.json
+coverage*.xml
+coverage*.info
+
+# Visual Studio code coverage results
+*.coverage
+*.coveragexml
+
+# NCrunch
+_NCrunch_*
+.*crunch*.local.xml
+nCrunchTemp_*
+
+# MightyMoose
+*.mm.*
+AutoTest.Net/
+
+# Web workbench (sass)
+.sass-cache/
+
+# Installshield output folder
+[Ee]xpress/
+
+# DocProject is a documentation generator add-in
+DocProject/buildhelp/
+DocProject/Help/*.HxT
+DocProject/Help/*.HxC
+DocProject/Help/*.hhc
+DocProject/Help/*.hhk
+DocProject/Help/*.hhp
+DocProject/Help/Html2
+DocProject/Help/html
+
+# Click-Once directory
+publish/
+
+# Publish Web Output
+*.[Pp]ublish.xml
+*.azurePubxml
+# Note: Comment the next line if you want to checkin your web deploy settings,
+# but database connection strings (with potential passwords) will be unencrypted
+*.pubxml
+*.publishproj
+
+# Microsoft Azure Web App publish settings. Comment the next line if you want to
+# checkin your Azure Web App publish settings, but sensitive information contained
+# in these scripts will be unencrypted
+PublishScripts/
+
+# NuGet Packages
+*.nupkg
+# NuGet Symbol Packages
+*.snupkg
+# The packages folder can be ignored because of Package Restore
+**/[Pp]ackages/*
+# except build/, which is used as an MSBuild target.
+!**/[Pp]ackages/build/
+# Uncomment if necessary however generally it will be regenerated when needed
+#!**/[Pp]ackages/repositories.config
+# NuGet v3's project.json files produces more ignorable files
+*.nuget.props
+*.nuget.targets
+
+# Microsoft Azure Build Output
+csx/
+*.build.csdef
+
+# Microsoft Azure Emulator
+ecf/
+rcf/
+
+# Windows Store app package directories and files
+AppPackages/
+BundleArtifacts/
+Package.StoreAssociation.xml
+_pkginfo.txt
+*.appx
+*.appxbundle
+*.appxupload
+
+# Visual Studio cache files
+# files ending in .cache can be ignored
+*.[Cc]ache
+# but keep track of directories ending in .cache
+!?*.[Cc]ache/
+
+# Others
+ClientBin/
+~$*
+*~
+*.dbmdl
+*.dbproj.schemaview
+*.jfm
+*.pfx
+*.publishsettings
+orleans.codegen.cs
+
+# Including strong name files can present a security risk
+# (https://github.com/github/gitignore/pull/2483#issue-259490424)
+#*.snk
+
+# Since there are multiple workflows, uncomment next line to ignore bower_components
+# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
+#bower_components/
+
+# RIA/Silverlight projects
+Generated_Code/
+
+# Backup & report files from converting an old project file
+# to a newer Visual Studio version. Backup files are not needed,
+# because we have git ;-)
+_UpgradeReport_Files/
+Backup*/
+UpgradeLog*.XML
+UpgradeLog*.htm
+ServiceFabricBackup/
+*.rptproj.bak
+
+# SQL Server files
+*.mdf
+*.ldf
+*.ndf
+
+# Business Intelligence projects
+*.rdl.data
+*.bim.layout
+*.bim_*.settings
+*.rptproj.rsuser
+*- [Bb]ackup.rdl
+*- [Bb]ackup ([0-9]).rdl
+*- [Bb]ackup ([0-9][0-9]).rdl
+
+# Microsoft Fakes
+FakesAssemblies/
+
+# GhostDoc plugin setting file
+*.GhostDoc.xml
+
+# Node.js Tools for Visual Studio
+.ntvs_analysis.dat
+node_modules/
+
+# Visual Studio 6 build log
+*.plg
+
+# Visual Studio 6 workspace options file
+*.opt
+
+# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
+*.vbw
+
+# Visual Studio 6 auto-generated project file (contains which files were open etc.)
+*.vbp
+
+# Visual Studio 6 workspace and project file (working project files containing files to include in project)
+*.dsw
+*.dsp
+
+# Visual Studio 6 technical files
+*.ncb
+*.aps
+
+# Visual Studio LightSwitch build output
+**/*.HTMLClient/GeneratedArtifacts
+**/*.DesktopClient/GeneratedArtifacts
+**/*.DesktopClient/ModelManifest.xml
+**/*.Server/GeneratedArtifacts
+**/*.Server/ModelManifest.xml
+_Pvt_Extensions
+
+# Paket dependency manager
+.paket/paket.exe
+paket-files/
+
+# FAKE - F# Make
+.fake/
+
+# CodeRush personal settings
+.cr/personal
+
+# Python Tools for Visual Studio (PTVS)
+__pycache__/
+*.pyc
+
+# Cake - Uncomment if you are using it
+# tools/**
+# !tools/packages.config
+
+# Tabs Studio
+*.tss
+
+# Telerik's JustMock configuration file
+*.jmconfig
+
+# BizTalk build output
+*.btp.cs
+*.btm.cs
+*.odx.cs
+*.xsd.cs
+
+# OpenCover UI analysis results
+OpenCover/
+
+# Azure Stream Analytics local run output
+ASALocalRun/
+
+# MSBuild Binary and Structured Log
+*.binlog
+
+# NVidia Nsight GPU debugger configuration file
+*.nvuser
+
+# MFractors (Xamarin productivity tool) working folder
+.mfractor/
+
+# Local History for Visual Studio
+.localhistory/
+
+# Visual Studio History (VSHistory) files
+.vshistory/
+
+# BeatPulse healthcheck temp database
+healthchecksdb
+
+# Backup folder for Package Reference Convert tool in Visual Studio 2017
+MigrationBackup/
+
+# Ionide (cross platform F# VS Code tools) working folder
+.ionide/
+
+# Fody - auto-generated XML schema
+FodyWeavers.xsd
+
+# VS Code files for those working on multiple tools
+.vscode/*
+!.vscode/settings.json
+!.vscode/tasks.json
+!.vscode/launch.json
+!.vscode/extensions.json
+*.code-workspace
+
+# Local History for Visual Studio Code
+.history/
+
+# Windows Installer files from build outputs
+*.cab
+*.msi
+*.msix
+*.msm
+*.msp
+
+# JetBrains Rider
+*.sln.iml
diff --git a/caf-logging-serilog/CafLoggingLoggerConfiguration.cs b/caf-logging-serilog/CafLoggingLoggerConfiguration.cs
new file mode 100644
index 0000000..4551558
--- /dev/null
+++ b/caf-logging-serilog/CafLoggingLoggerConfiguration.cs
@@ -0,0 +1,62 @@
+/**
+ * Copyright 2019-2022 Micro Focus or one of its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+using Serilog;
+using Serilog.Core;
+using Serilog.Events;
+using Serilog.Expressions;
+using Serilog.Templates;
+using System;
+
+namespace MicroFocus.CafApi.CafLoggingSerilog
+{
+ public static class CafLoggingLoggerConfiguration
+ {
+ private const string DefaultTemplate =
+ "[{UtcDateTime(@t):yyyy-MM-dd HH:mm:ss.fffZ} {FormatThreadAndProcessId(ProcessId,ThreadId)} {Log(@l):5} {Coalesce(Sanitize(tenantId, 12, 12), '-')} " +
+ "{Coalesce(Sanitize(correlationId, 4, 4), '-')}] {Sanitize(logger, 30, 30)}: {ConvertMessageAndExceptionToJsonIfUnsafe(@m,@x)}\n";
+
+ private static readonly StaticMemberNameResolver sanitizerFunctions = new(typeof(Sanitizer));
+ private static readonly LoggingLevelSwitch defaultLoggingLevelSwitch = new(LogEventLevel.Information);
+ private static readonly string Caf_log_level_env = Environment.GetEnvironmentVariable("CAF_LOG_LEVEL");
+
+ public static LoggerConfiguration CreateLogConfiguration()
+ {
+ return new LoggerConfiguration()
+ .WriteTo.Console(
+ new ExpressionTemplate(
+ DefaultTemplate,
+ nameResolver: sanitizerFunctions), // References the functions used in the default template
+ standardErrorFromLevel: LogEventLevel.Verbose // Redirects the logs to stderr
+ )
+ .Enrich.FromLogContext()
+ .Enrich.WithThreadId()
+ .Enrich.WithProcessId()
+ .MinimumLevel.ControlledBy(SetLog());
+ }
+
+ private static LoggingLevelSwitch SetLog()
+ {
+ try
+ {
+ var level = (LogEventLevel)Enum.Parse(typeof(LogEventLevel), Caf_log_level_env);
+ return new LoggingLevelSwitch(level);
+ }
+ catch (ArgumentException) {
+ return defaultLoggingLevelSwitch;
+ }
+ }
+ }
+}
diff --git a/caf-logging-serilog/MicroFocus.CafApi.CafLoggingSerilog.csproj b/caf-logging-serilog/MicroFocus.CafApi.CafLoggingSerilog.csproj
new file mode 100644
index 0000000..28bb2eb
--- /dev/null
+++ b/caf-logging-serilog/MicroFocus.CafApi.CafLoggingSerilog.csproj
@@ -0,0 +1,19 @@
+
+
+
+ netstandard2.0
+ MicroFocus.CafApi.CafLoggingSerilog
+ Library
+ 9.0
+ enable
+
+
+
+
+
+
+
+
+
+
+
diff --git a/caf-logging-serilog/MicroFocus.CafApi.CafLoggingSerilog.sln b/caf-logging-serilog/MicroFocus.CafApi.CafLoggingSerilog.sln
new file mode 100644
index 0000000..1152820
--- /dev/null
+++ b/caf-logging-serilog/MicroFocus.CafApi.CafLoggingSerilog.sln
@@ -0,0 +1,25 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Version 17
+VisualStudioVersion = 17.0.32112.339
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MicroFocus.CafApi.CafLoggingSerilog", "MicroFocus.CafApi.CafLoggingSerilog.csproj", "{13F4E0DF-1813-44B3-8629-49A23CC0490E}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {13F4E0DF-1813-44B3-8629-49A23CC0490E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {13F4E0DF-1813-44B3-8629-49A23CC0490E}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {13F4E0DF-1813-44B3-8629-49A23CC0490E}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {13F4E0DF-1813-44B3-8629-49A23CC0490E}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {89CE60D1-AA45-4C09-A38B-054C7BED98BC}
+ EndGlobalSection
+EndGlobal
diff --git a/caf-logging-serilog/README.md b/caf-logging-serilog/README.md
new file mode 100644
index 0000000..1f6e281
--- /dev/null
+++ b/caf-logging-serilog/README.md
@@ -0,0 +1,69 @@
+# CAF Logging Serilog
+This project configures Serilog to meet the CAF Logging Standard.
+
+The log level is controllable via an environment variable.
+- The `CAF_LOG_LEVEL` environment variable can be used to configure the required volume of logging.
+- By default `INFO`-level logging is used.
+
+All logs are being redirected to `stderr`.
+A consistent log message format is used.
+
+The header information is in square brackets.
+Fixed size columns are used so that messages align vertically.
+Missing or inapplicable header fields are replaced with a dash.
+Log Injection attacks are prevented.
+
+Any unsafe characters found in the Tenant Id, Correlation Id, or Logger are removed.
+The log message is JSON-encoded if it contains any control characters (including newlines) or any non-ASCII characters.
+Exception stack traces are JSON-encoded so that they do not span multiple lines.
+
+## Dependency
+
+Add the nuget package `MicroFocus.CafApi.CafLoggingSerilog`
+
+## Pattern
+
+`[{@t:yyyy-MM-dd HH:mm:ss.fffZ} {Tid(ProcessId,ThreadId)} {Log(@l):5} {Sanitize(tenantId, 12, 12)} {Sanitize(correlationId, 4, 4)}] {Sanitize(logger, 30, 30)}: {MaybeJsonMsgAndEx(@m,@x)}\n`
+
+## Examples
+
+`[2022-05-10 13:29:45.444Z #217.001 WARN john-tenant Cidi] c.m.d.f.f.f.FieldFullTextFixer: "Greek test: κόσμε"`
+
+To log the tenant and correlation ids the service using this configuration must use Serilog's MDC.
+
+Example commands:
+
+ using (LogContext.PushProperty("tenantId", "sample-tenant"))
+ using (LogContext.PushProperty("correlationId", "Abc123"))
+
+If the tenant or correlation id are not supplied the logger will substitute them with a dash and pad the rest of their character allotment
+with spaces. The logger will also pad any tenant id shorter than 12 characters to the 12 characters limit.
+This is to aid readability of the logs by aligning the log statements.
+
+To use this logging configuration simply add the following nuget package:
+
+ `MicroFocus.CafApi.CafLoggingSerilog`
+
+### Basic
+ Log.Logger = CafLoggingLoggerConfiguration
+ .GetLoggerConfig()
+ .CreateLogger();
+
+### With switchLevel ( minimum logging level )
+
+ var levelSwitch = new LoggingLevelSwitch();
+ levelSwitch.MinimumLevel = LogEventLevel.Verbose;
+ Log.Logger = CafLoggingLoggerConfiguration
+ .GetLoggerConfig(levelSwitch)
+ .CreateLogger();
+
+### With configuration file
+
+ var config_path = "path\\to\\file\\appsettings.json";
+ var configuration = new ConfigurationBuilder()
+ .AddJsonFile(config_path)
+ .Build();
+ Log.Logger = CafLoggingLoggerConfiguration
+ .GetLoggerConfig()
+ .ReadFrom.Configuration(configuration)
+ .CreateLogger();
diff --git a/caf-logging-serilog/SanitizedMessage.cs b/caf-logging-serilog/SanitizedMessage.cs
new file mode 100644
index 0000000..64c8671
--- /dev/null
+++ b/caf-logging-serilog/SanitizedMessage.cs
@@ -0,0 +1,28 @@
+/**
+ * Copyright 2019-2022 Micro Focus or one of its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+namespace MicroFocus.CafApi.CafLoggingSerilog
+{
+ internal class SanitizedMessage
+ {
+ public string message;
+
+ public SanitizedMessage(string message)
+ {
+ this.message = message;
+ }
+ }
+}
diff --git a/caf-logging-serilog/SanitizedMessageException.cs b/caf-logging-serilog/SanitizedMessageException.cs
new file mode 100644
index 0000000..892fc3b
--- /dev/null
+++ b/caf-logging-serilog/SanitizedMessageException.cs
@@ -0,0 +1,35 @@
+/**
+ * Copyright 2019-2022 Micro Focus or one of its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+namespace MicroFocus.CafApi.CafLoggingSerilog
+{
+ internal class SanitizedMessageException
+ {
+ public string message;
+ public string? exception;
+
+ public SanitizedMessageException(string message)
+ {
+ this.message = message;
+ }
+
+ public SanitizedMessageException(string message, string exception)
+ {
+ this.message = message;
+ this.exception = exception;
+ }
+ }
+}
diff --git a/caf-logging-serilog/Sanitizer.cs b/caf-logging-serilog/Sanitizer.cs
new file mode 100644
index 0000000..a1f319c
--- /dev/null
+++ b/caf-logging-serilog/Sanitizer.cs
@@ -0,0 +1,143 @@
+/**
+ * Copyright 2019-2022 Micro Focus or one of its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+using Newtonsoft.Json;
+using Serilog.Events;
+using System;
+using System.Text.RegularExpressions;
+
+namespace MicroFocus.CafApi.CafLoggingSerilog
+{
+ static class Sanitizer
+ {
+ private const string ForbiddenPattern = "[^\\w\\s\\-.]*";
+ private readonly static Regex rgx = new(ForbiddenPattern);
+
+ public static LogEventPropertyValue? Log(LogEventPropertyValue? value)
+ {
+ if (value is ScalarValue)
+ {
+ var level = value.ToString();
+ return level switch
+ {
+ "Information" or "Warning" => new ScalarValue(level.ToUpper().Substring(0, 4).PadRight(5, ' ')),
+ _ => new ScalarValue(level.ToUpper().Substring(0, 5)),
+ };
+ }
+
+ return null;
+ }
+
+ public static LogEventPropertyValue? FormatThreadAndProcessId(LogEventPropertyValue? processId, LogEventPropertyValue? ThreadId)
+ {
+ if (processId is ScalarValue && ThreadId is ScalarValue)
+ {
+ var threadId = ThreadId.ToString();
+ return new ScalarValue("#" + processId.ToString().Substring(0, 3) + "." + threadId.PadLeft(3, '0'));
+ }
+
+ return null;
+ }
+
+ public static LogEventPropertyValue? Sanitize(LogEventPropertyValue? value, LogEventPropertyValue length, LogEventPropertyValue padding)
+ {
+
+ if (value is ScalarValue)
+ {
+ int valueLength, valuePadding;
+ try
+ {
+ valueLength = Convert.ToInt32(length.ToString());
+ valuePadding = Convert.ToInt32(padding.ToString());
+ }
+ catch (FormatException)
+ {
+ valueLength = 4;
+ valuePadding = 4;
+ }
+ var newValue = rgx.Replace(value.ToString(), "");
+ if (valueLength <= newValue.Length)
+ {
+ newValue = newValue.Substring(0, valueLength);
+ }
+ newValue = newValue.PadRight(valuePadding, ' ');
+ return new ScalarValue(newValue);
+ }
+
+ return null;
+ }
+
+ public static LogEventPropertyValue? ConvertMessageAndExceptionToJsonIfUnsafe(LogEventPropertyValue? message, LogEventPropertyValue? exception)
+ {
+
+ if (
+ message is ScalarValue sm &&
+ sm.Value is string rawMessage
+ )
+ {
+ var raw_message = message.ToString();
+ if (IsMessageSafeToLog(raw_message) && null == exception)
+ {
+ return new ScalarValue(rawMessage);
+ }
+ else
+ {
+ if (exception is ScalarValue)
+ {
+ var output = JsonConvert.SerializeObject(new SanitizedMessageException(rawMessage, exception.ToString()));
+ return new ScalarValue(output);
+ }
+ else
+ {
+ var jsonData = JsonConvert.SerializeObject(new SanitizedMessage(rawMessage));
+ return new ScalarValue(jsonData);
+ }
+ }
+ }
+ return null;
+ }
+
+ private static bool IsMessageSafeToLog(string message)
+ {
+ if (string.IsNullOrWhiteSpace(message))
+ {
+ return true;
+ }
+
+ if (message.StartsWith("{") || message.StartsWith("\"{"))
+ {
+ return false;
+ }
+
+ return ContainSafeCharacters(message);
+ }
+
+ private static bool ContainSafeCharacters(string message)
+ {
+ int min = Convert.ToInt32("0x20", 16);
+ int max = Convert.ToInt32("0x7F", 16);
+
+ foreach (char c in message)
+ {
+ int x = c;
+ if (x < min || x >= max)
+ {
+ return false;
+ }
+ }
+ return true;
+ }
+ }
+}
diff --git a/caf-logging-serilog/pom.xml b/caf-logging-serilog/pom.xml
new file mode 100644
index 0000000..b650d6e
--- /dev/null
+++ b/caf-logging-serilog/pom.xml
@@ -0,0 +1,152 @@
+
+
+
+
+ 4.0.0
+
+
+ com.github.cafapi.logging
+ caf-logging
+ 2.1.0-SNAPSHOT
+
+
+ caf-logging-serilog
+ pom
+
+
+ ${project.build.directory}
+
+
+
+ ${project.basedir}
+
+
+
+ org.codehaus.mojo
+ exec-maven-plugin
+
+
+ ${RE_BUILD_TYPE}
+ ${project.version}
+
+
+
+
+ exec-dotnet-clean
+ clean
+
+ exec
+
+
+ dotnet
+
+ clean
+
+
+
+
+ exec-dotnet-restore
+ initialize
+
+ exec
+
+
+ dotnet
+
+ restore
+
+
+
+
+ exec-dotnet-build
+ compile
+
+ exec
+
+
+ dotnet
+
+ build
+
+
+
+
+ exec-dotnet-test
+ test
+
+ exec
+
+
+ dotnet
+
+ test
+
+
+
+
+ exec-dotnet-pack
+ package
+
+ exec
+
+
+ dotnet
+
+ pack
+ --no-build
+
+
+
+
+ exec-dotnet-pack-for-deploy
+ deploy
+
+ exec
+
+
+ dotnet
+
+ pack
+ --no-build
+ --output
+ ${nugetOutputFolder}
+
+
+
+
+
+
+ com.mycila
+ license-maven-plugin
+
+
+ *.csproj
+ *.sln
+ .vs/**
+ obj/**
+ bin/**
+
+
+
+
+
+
+
diff --git a/official-build.props b/official-build.props
index 2c3542a..7caa7eb 100644
--- a/official-build.props
+++ b/official-build.props
@@ -1 +1 @@
-SEPG_BUILD_ENV_IMAGE=cafapi/opensuse-jdk8-maven:1.0.0
+SEPG_BUILD_ENV_IMAGE=cafapi/buildenv-dotnet:1.0.0
diff --git a/pom.xml b/pom.xml
index b657202..6bc7dd3 100644
--- a/pom.xml
+++ b/pom.xml
@@ -69,6 +69,7 @@
caf-logging-logback
caf-logging-logback-converters
caf-logging-logback-access-converters
+ caf-logging-serilog
@@ -144,4 +145,16 @@
+
+
+
+
+ org.codehaus.mojo
+ exec-maven-plugin
+ 3.0.0
+
+
+
+
+