Skip to content

Commit fcd389c

Browse files
committed
Added NetStandardDemo to reproduce issue 290.
1 parent b0295fa commit fcd389c

File tree

5 files changed

+115
-0
lines changed

5 files changed

+115
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>netcoreapp3.1</TargetFramework>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<ProjectReference Include="..\NetStandardDemoLib\NetStandardDemoLib.csproj" />
10+
</ItemGroup>
11+
12+
</Project>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System;
2+
using System.Threading;
3+
using NetStandardDemoLib;
4+
using Serilog;
5+
6+
namespace NetStandardDemoApp
7+
{
8+
public static class Program
9+
{
10+
public static void Main()
11+
{
12+
Log.Logger = Initializer.CreateLoggerConfiguration().CreateLogger();
13+
14+
Log.Debug("Getting started");
15+
16+
Log.Information("Hello {Name} from thread {ThreadId}", Environment.GetEnvironmentVariable("USERNAME"), Thread.CurrentThread.ManagedThreadId);
17+
18+
Log.Warning("No coins remain at position {@Position}", new { Lat = 25, Long = 134 });
19+
}
20+
}
21+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
using System.Collections.ObjectModel;
2+
using System.Data;
3+
using Serilog;
4+
using Serilog.Sinks.MSSqlServer;
5+
using Serilog.Sinks.MSSqlServer.Sinks.MSSqlServer.Options;
6+
7+
namespace NetStandardDemoLib
8+
{
9+
public static class Initializer
10+
{
11+
private const string _connectionString = "Server=localhost;Database=LogTest;Integrated Security=SSPI;";
12+
private const string _tableName = "LogEvents";
13+
14+
public static LoggerConfiguration CreateLoggerConfiguration()
15+
{
16+
return new LoggerConfiguration()
17+
.Enrich.FromLogContext()
18+
.WriteTo.MSSqlServer(
19+
_connectionString,
20+
new SinkOptions
21+
{
22+
TableName = _tableName,
23+
AutoCreateSqlTable = true
24+
},
25+
columnOptions: BuildColumnOptions());
26+
}
27+
28+
private static ColumnOptions BuildColumnOptions()
29+
{
30+
var columnOptions = new ColumnOptions
31+
{
32+
TimeStamp =
33+
{
34+
ColumnName = "TimeStampUTC",
35+
ConvertToUtc = true,
36+
},
37+
38+
AdditionalColumns = new Collection<SqlColumn>
39+
{
40+
new SqlColumn { DataType = SqlDbType.NChar, ColumnName = "MachineName" },
41+
new SqlColumn { DataType = SqlDbType.NChar, ColumnName = "ProcessName" },
42+
new SqlColumn { DataType = SqlDbType.NChar, ColumnName = "ThreadId" },
43+
new SqlColumn { DataType = SqlDbType.NChar, ColumnName = "CallerName" },
44+
new SqlColumn { DataType = SqlDbType.NChar, ColumnName = "SourceFile" },
45+
new SqlColumn { DataType = SqlDbType.NChar, ColumnName = "LineNumber" }
46+
}
47+
};
48+
49+
columnOptions.Store.Remove(StandardColumn.Properties);
50+
51+
return columnOptions;
52+
}
53+
}
54+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netstandard2.0</TargetFramework>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<ProjectReference Include="..\..\..\src\Serilog.Sinks.MSSqlServer\Serilog.Sinks.MSSqlServer.csproj" />
9+
</ItemGroup>
10+
11+
</Project>

serilog-sinks-mssqlserver.sln

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
3030
README.md = README.md
3131
EndProjectSection
3232
EndProject
33+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NetStandardDemoLib", "sample\NetStandardDemo\NetStandardDemoLib\NetStandardDemoLib.csproj", "{8E69E31B-61C7-4175-B886-9C2078FCA477}"
34+
EndProject
35+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NetStandardDemoApp", "sample\NetStandardDemo\NetStandardDemoApp\NetStandardDemoApp.csproj", "{F908C46D-E72E-41E4-975D-73733294F93F}"
36+
EndProject
37+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "NetStandardDemo", "NetStandardDemo", "{7B2B80DE-427A-4FEC-A7CE-7AD81FED73DE}"
38+
EndProject
3339
Global
3440
GlobalSection(SolutionConfigurationPlatforms) = preSolution
3541
Debug|Any CPU = Debug|Any CPU
@@ -60,6 +66,14 @@ Global
6066
{98F21125-AF7A-46E8-8C08-E3E4F5DBEDB9}.Debug|Any CPU.Build.0 = Debug|Any CPU
6167
{98F21125-AF7A-46E8-8C08-E3E4F5DBEDB9}.Release|Any CPU.ActiveCfg = Release|Any CPU
6268
{98F21125-AF7A-46E8-8C08-E3E4F5DBEDB9}.Release|Any CPU.Build.0 = Release|Any CPU
69+
{8E69E31B-61C7-4175-B886-9C2078FCA477}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
70+
{8E69E31B-61C7-4175-B886-9C2078FCA477}.Debug|Any CPU.Build.0 = Debug|Any CPU
71+
{8E69E31B-61C7-4175-B886-9C2078FCA477}.Release|Any CPU.ActiveCfg = Release|Any CPU
72+
{8E69E31B-61C7-4175-B886-9C2078FCA477}.Release|Any CPU.Build.0 = Release|Any CPU
73+
{F908C46D-E72E-41E4-975D-73733294F93F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
74+
{F908C46D-E72E-41E4-975D-73733294F93F}.Debug|Any CPU.Build.0 = Debug|Any CPU
75+
{F908C46D-E72E-41E4-975D-73733294F93F}.Release|Any CPU.ActiveCfg = Release|Any CPU
76+
{F908C46D-E72E-41E4-975D-73733294F93F}.Release|Any CPU.Build.0 = Release|Any CPU
6377
EndGlobalSection
6478
GlobalSection(SolutionProperties) = preSolution
6579
HideSolutionNode = FALSE
@@ -71,6 +85,9 @@ Global
7185
{7DC530B1-68FD-4F07-A2F9-910C338562C1} = {AA346332-5BAF-47F1-B8FB-7600ED61265D}
7286
{04F523D9-F00B-4C63-9287-31A244378E06} = {AA346332-5BAF-47F1-B8FB-7600ED61265D}
7387
{98F21125-AF7A-46E8-8C08-E3E4F5DBEDB9} = {AA346332-5BAF-47F1-B8FB-7600ED61265D}
88+
{8E69E31B-61C7-4175-B886-9C2078FCA477} = {7B2B80DE-427A-4FEC-A7CE-7AD81FED73DE}
89+
{F908C46D-E72E-41E4-975D-73733294F93F} = {7B2B80DE-427A-4FEC-A7CE-7AD81FED73DE}
90+
{7B2B80DE-427A-4FEC-A7CE-7AD81FED73DE} = {AA346332-5BAF-47F1-B8FB-7600ED61265D}
7491
EndGlobalSection
7592
GlobalSection(ExtensibilityGlobals) = postSolution
7693
SolutionGuid = {AAA6BF8D-7B53-4A5F-A79A-D1B306383B45}

0 commit comments

Comments
 (0)