Skip to content

Commit

Permalink
Merge pull request #240 from serilog/dev
Browse files Browse the repository at this point in the history
Release 5.2.0
  • Loading branch information
ckadluba authored Mar 27, 2020
2 parents 9a978c4 + 01c2310 commit 7be4936
Show file tree
Hide file tree
Showing 38 changed files with 902 additions and 215 deletions.
3 changes: 3 additions & 0 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Code of Conduct

Please refer to the [Serilog Code of Conduct](https://github.com/serilog/serilog/blob/dev/CODE_OF_CONDUCT.md) which covers all repositories within the Serilog Organization.
18 changes: 12 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ All sink configuration methods accept the following arguments, though not necess
* `batchPostingLimit`
* `period`
* `formatProvider`
* `logEventFormatter`

### Basic Arguments

Expand All @@ -54,6 +55,8 @@ Consider increasing the batch size in high-volume logging environments. In one t

Refer to the Serilog Wiki's explanation of [Format Providers](https://github.com/serilog/serilog/wiki/Formatting-Output#format-providers) for details about the `formatProvider` arguments.

The parameter `logEventFormatter` can be used to specify a custom renderer implementing `ITextFormatter` which will be used to generate the contents of the `LogEvent`column. If the parameter is omitted or set to null, the default internal JSON formatter will be used. For more information about custom text formatters refer to the Serilog documentation [Custom text formatters](https://github.com/serilog/serilog/wiki/Formatting-Output#custom-text-formatters).

### Platform-Specific Arguments

These additional arguments are accepted when the sink is configured from a library or application that supports the .NET Standard-style _Microsoft.Extensions.Configuration_ packages. They are optional.
Expand Down Expand Up @@ -154,6 +157,7 @@ The constructor accepts most of the same arguments, and like other Serilog audit
* `autoCreateSqlTable`
* `columnOptions`
* `formatProvider`
* `logEventFormatter`

The `restrictedToMinimumLevel` parameter is not available because all events written to an audit sink are required to succeed.

Expand Down Expand Up @@ -408,6 +412,8 @@ This column stores log event property values as JSON. Typically you will use eit

The `ExcludeAddtionalProperties` and `ExcludeStandardColumns` properties are described in the [Custom Property Columns](#custom-property-columns) topic.

The content of this column is rendered as JSON by default or with a custom ITextFormatter passed by the caller as parameter `logEventFormatter`. Details can be found in [Sink Configuration Options](#sink-configuration-options).

## Custom Property Columns

By default, any log event properties you include in your log statements will be saved to the XML `Properties` column or the JSON `LogEvent` column. But they can also be stored in their own individual columns via the `AdditionalColumns` collection. This adds overhead to write operations but is very useful for frequently-queried properties. Only `ColumnName` is required; the default configuration is `varchar(max)`.
Expand Down Expand Up @@ -554,12 +560,12 @@ Keys and values are case-sensitive. Case must match **_exactly_** as shown below
<remove Name="Properties"/>
</RemoveStandardColumns>
<Columns>
<add columnName="EventType" DataType="int"/>
<add columnName="Release"
dataType="varchar"
dataLength="64"
allowNull="true"
nonClusteredIndex="false"/>
<add ColumnName="EventType" DataType="int"/>
<add ColumnName="Release"
DataType="varchar"
DataLength="64"
AllowNull="true"
NonClusteredIndex="false"/>
</Columns>
<Exception ColumnName="Ex" DataLength="512"/>
<Id NonClusteredIndex="true"/>
Expand Down
5 changes: 0 additions & 5 deletions assets/CommonAssemblyInfo.cs

This file was deleted.

30 changes: 30 additions & 0 deletions sample/AppConfigDemo/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="MSSqlServerSettingsSection" type="Serilog.Configuration.MSSqlServerConfigurationSection, Serilog.Sinks.MSSqlServer" />
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
<MSSqlServerSettingsSection>
<AddStandardColumns>
<add Name="LogEvent" />
</AddStandardColumns>
<RemoveStandardColumns>
<remove Name="Properties" />
</RemoveStandardColumns>
<TimeStamp ColumnName="TimeStampAlternative" ConvertToUtc="true" />
</MSSqlServerSettingsSection>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.6.0" newVersion="4.0.6.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Extensions.Primitives" publicKeyToken="adb9793829ddae60" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.1.2.0" newVersion="3.1.2.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
83 changes: 83 additions & 0 deletions sample/AppConfigDemo/AppConfigDemo.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?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>{7DC530B1-68FD-4F07-A2F9-910C338562C1}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>AppConfigDemo</RootNamespace>
<AssemblyName>AppConfigDemo</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
</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="Microsoft.Extensions.Configuration.Abstractions, Version=3.1.2.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.Extensions.Configuration.Abstractions.3.1.2\lib\netstandard2.0\Microsoft.Extensions.Configuration.Abstractions.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Extensions.Primitives, Version=3.1.2.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.Extensions.Primitives.3.1.2\lib\netstandard2.0\Microsoft.Extensions.Primitives.dll</HintPath>
</Reference>
<Reference Include="Serilog, Version=2.0.0.0, Culture=neutral, PublicKeyToken=24c2f752a8e58a10, processorArchitecture=MSIL">
<HintPath>..\..\packages\Serilog.2.6.0\lib\net46\Serilog.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Buffers, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\..\packages\System.Buffers.4.4.0\lib\netstandard2.0\System.Buffers.dll</HintPath>
</Reference>
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Memory, Version=4.0.1.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\..\packages\System.Memory.4.5.2\lib\netstandard2.0\System.Memory.dll</HintPath>
</Reference>
<Reference Include="System.Numerics" />
<Reference Include="System.Numerics.Vectors, Version=4.1.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\packages\System.Numerics.Vectors.4.4.0\lib\net46\System.Numerics.Vectors.dll</HintPath>
</Reference>
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=4.0.6.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\packages\System.Runtime.CompilerServices.Unsafe.4.7.0\lib\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
</Reference>
<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="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Serilog.Sinks.MSSqlServer\Serilog.Sinks.MSSqlServer.csproj">
<Project>{803cd13a-d54b-4cec-a55f-e22ae3d93b3c}</Project>
<Name>Serilog.Sinks.MSSqlServer</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
41 changes: 41 additions & 0 deletions sample/AppConfigDemo/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using Serilog;
using Serilog.Events;
using Serilog.Sinks.MSSqlServer;
using System;
using System.Threading;

namespace AppConfigDemo
{
public class Program
{
const string _connectionString = "Server=localhost;Database=LogTest;Integrated Security=SSPI;";
const string _schemaName = "dbo";
const string _tableName = "LogEvents";

public static void Main()
{
Log.Logger = new LoggerConfiguration().WriteTo
.MSSqlServer(
connectionString: _connectionString,
tableName: _tableName,
restrictedToMinimumLevel: LogEventLevel.Debug,
batchPostingLimit: MSSqlServerSink.DefaultBatchPostingLimit,
period: null,
formatProvider: null,
autoCreateSqlTable: true,
columnOptions: null,
schemaName: _schemaName,
logEventFormatter: null)
.CreateLogger();

Log.Debug("Getting started");

Log.Information("Hello {Name} from thread {ThreadId}", Environment.GetEnvironmentVariable("USERNAME"),
Thread.CurrentThread.ManagedThreadId);

Log.Warning("No coins remain at position {@Position}", new { Lat = 25, Long = 134 });

Log.CloseAndFlush();
}
}
}
36 changes: 36 additions & 0 deletions sample/AppConfigDemo/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -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("AppConfigDemo")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("AppConfigDemo")]
[assembly: AssemblyCopyright("Copyright © 2020")]
[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("7dc530b1-68fd-4f07-a2f9-910c338562c1")]

// 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")]
11 changes: 11 additions & 0 deletions sample/AppConfigDemo/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.Extensions.Configuration.Abstractions" version="3.1.2" targetFramework="net461" />
<package id="Microsoft.Extensions.Primitives" version="3.1.2" targetFramework="net461" />
<package id="Serilog" version="2.6.0" targetFramework="net461" />
<package id="Serilog.Settings.AppSettings" version="2.2.2" targetFramework="net461" />
<package id="System.Buffers" version="4.4.0" targetFramework="net461" />
<package id="System.Memory" version="4.5.2" targetFramework="net461" />
<package id="System.Numerics.Vectors" version="4.4.0" targetFramework="net461" />
<package id="System.Runtime.CompilerServices.Unsafe" version="4.7.0" targetFramework="net461" />
</packages>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Serilog.Sinks.MSSqlServer\Serilog.Sinks.MSSqlServer.csproj" />
</ItemGroup>

</Project>
19 changes: 19 additions & 0 deletions sample/CustomLogEventFormatterDemo/FlatLogEventFormatter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Serilog.Events;
using Serilog.Formatting;
using System.IO;
using System.Linq;

namespace CustomLogEventFormatterDemo
{
public class FlatLogEventFormatter : ITextFormatter
{
public void Format(LogEvent logEvent, TextWriter output)
{
logEvent.Properties.ToList().ForEach(e =>
{
output.Write($"{e.Key}={e.Value} ");
});
output.WriteLine();
}
}
}
57 changes: 57 additions & 0 deletions sample/CustomLogEventFormatterDemo/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using Serilog;
using Serilog.Sinks.MSSqlServer;
using System;
using System.Threading;

namespace CustomLogEventFormatterDemo
{
public class Program
{
const string _connectionString = "Server=localhost;Database=LogTest;Integrated Security=SSPI;";
const string _schemaName = "dbo";
const string _tableName = "LogEvents";

public static void Main()
{
var options = new ColumnOptions();
options.Store.Add(StandardColumn.LogEvent);
var customFormatter = new FlatLogEventFormatter();
Log.Logger = new LoggerConfiguration()
.WriteTo.MSSqlServer(_connectionString,
_tableName,
appConfiguration: null,
restrictedToMinimumLevel: Serilog.Events.LogEventLevel.Verbose,
batchPostingLimit: 50,
period: null,
formatProvider: null,
autoCreateSqlTable: true,
columnOptions: options,
columnOptionsSection: null,
schemaName: _schemaName,
logEventFormatter: customFormatter)
.CreateLogger();

try
{
Log.Debug("Getting started");

Log.Information("Hello {Name} from thread {ThreadId}", Environment.GetEnvironmentVariable("USERNAME"), Thread.CurrentThread.ManagedThreadId);

Log.Warning("No coins remain at position {@Position}", new { Lat = 25, Long = 134 });

Fail();
}
catch (DivideByZeroException e)
{
Log.Error(e, "Division by zero");
}

Log.CloseAndFlush();
}

static void Fail()
{
throw new DivideByZeroException();
}
}
}
18 changes: 18 additions & 0 deletions sample/WorkerServiceDemo/CustomLogEventFormatter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using Serilog.Events;
using Serilog.Formatting;
using System.IO;
using System.Linq;

namespace WorkerServiceDemo
{
public class CustomLogEventFormatter : ITextFormatter
{
public static CustomLogEventFormatter Formatter { get; } = new CustomLogEventFormatter();

public void Format(LogEvent logEvent, TextWriter output)
{
logEvent.Properties.ToList()
.ForEach(e => output.Write($"{e.Key}={e.Value} "));
}
}
}
Loading

0 comments on commit 7be4936

Please sign in to comment.