├── .editorconfig
├── .gitattributes
├── .gitignore
├── Build.ps1
├── CHANGES.md
├── LICENSE
├── README.md
├── appveyor.yml
├── assets
├── CommonAssemblyInfo.cs
└── Serilog.snk
├── global.json
├── serilog-sinks-nlog.sln
├── src
└── Serilog.Sinks.NLog
│ ├── LoggerConfigurationsNLogExtensions.cs
│ ├── Properties
│ └── AssemblyInfo.cs
│ ├── Serilog.Sinks.NLog.xproj
│ ├── Sinks
│ └── NLog
│ │ └── NLogSink.cs
│ └── project.json
└── test
└── Serilog.Sinks.NLog.Tests
├── Properties
└── AssemblyInfo.cs
├── Serilog.Sinks.NLog.Tests.xproj
├── Sinks
└── NLog
│ └── NLogSinkTest.cs
└── project.json
/.editorconfig:
--------------------------------------------------------------------------------
1 | root=true
2 |
3 | [*]
4 | indent_style = space
5 | indent_size = 4
6 |
7 | [project.json]
8 | indent_style = space
9 | indent_size = 2
10 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 |
3 | * text=auto
4 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 |
4 | # User-specific files
5 | *.suo
6 | *.user
7 | *.userosscache
8 | *.sln.docstates
9 |
10 | # User-specific files (MonoDevelop/Xamarin Studio)
11 | *.userprefs
12 |
13 | # Build results
14 | [Dd]ebug/
15 | [Dd]ebugPublic/
16 | [Rr]elease/
17 | [Rr]eleases/
18 | x64/
19 | x86/
20 | bld/
21 | [Bb]in/
22 | [Oo]bj/
23 |
24 | # Visual Studio 2015 cache/options directory
25 | .vs/
26 | # Uncomment if you have tasks that create the project's static files in wwwroot
27 | #wwwroot/
28 |
29 | # MSTest test Results
30 | [Tt]est[Rr]esult*/
31 | [Bb]uild[Ll]og.*
32 |
33 | # NUNIT
34 | *.VisualState.xml
35 | TestResult.xml
36 |
37 | # Build Results of an ATL Project
38 | [Dd]ebugPS/
39 | [Rr]eleasePS/
40 | dlldata.c
41 |
42 | # DNX
43 | project.lock.json
44 | artifacts/
45 |
46 | *_i.c
47 | *_p.c
48 | *_i.h
49 | *.ilk
50 | *.meta
51 | *.obj
52 | *.pch
53 | *.pdb
54 | *.pgc
55 | *.pgd
56 | *.rsp
57 | *.sbr
58 | *.tlb
59 | *.tli
60 | *.tlh
61 | *.tmp
62 | *.tmp_proj
63 | *.log
64 | *.vspscc
65 | *.vssscc
66 | .builds
67 | *.pidb
68 | *.svclog
69 | *.scc
70 |
71 | # Chutzpah Test files
72 | _Chutzpah*
73 |
74 | # Visual C++ cache files
75 | ipch/
76 | *.aps
77 | *.ncb
78 | *.opendb
79 | *.opensdf
80 | *.sdf
81 | *.cachefile
82 |
83 | # Visual Studio profiler
84 | *.psess
85 | *.vsp
86 | *.vspx
87 | *.sap
88 |
89 | # TFS 2012 Local Workspace
90 | $tf/
91 |
92 | # Guidance Automation Toolkit
93 | *.gpState
94 |
95 | # ReSharper is a .NET coding add-in
96 | _ReSharper*/
97 | *.[Rr]e[Ss]harper
98 | *.DotSettings.user
99 |
100 | # JustCode is a .NET coding add-in
101 | .JustCode
102 |
103 | # TeamCity is a build add-in
104 | _TeamCity*
105 |
106 | # DotCover is a Code Coverage Tool
107 | *.dotCover
108 |
109 | # NCrunch
110 | _NCrunch_*
111 | .*crunch*.local.xml
112 | nCrunchTemp_*
113 |
114 | # MightyMoose
115 | *.mm.*
116 | AutoTest.Net/
117 |
118 | # Web workbench (sass)
119 | .sass-cache/
120 |
121 | # Installshield output folder
122 | [Ee]xpress/
123 |
124 | # DocProject is a documentation generator add-in
125 | DocProject/buildhelp/
126 | DocProject/Help/*.HxT
127 | DocProject/Help/*.HxC
128 | DocProject/Help/*.hhc
129 | DocProject/Help/*.hhk
130 | DocProject/Help/*.hhp
131 | DocProject/Help/Html2
132 | DocProject/Help/html
133 |
134 | # Click-Once directory
135 | publish/
136 |
137 | # Publish Web Output
138 | *.[Pp]ublish.xml
139 | *.azurePubxml
140 | # TODO: Comment the next line if you want to checkin your web deploy settings
141 | # but database connection strings (with potential passwords) will be unencrypted
142 | *.pubxml
143 | *.publishproj
144 |
145 | # NuGet Packages
146 | *.nupkg
147 | # The packages folder can be ignored because of Package Restore
148 | **/packages/*
149 | # except build/, which is used as an MSBuild target.
150 | !**/packages/build/
151 | # Uncomment if necessary however generally it will be regenerated when needed
152 | #!**/packages/repositories.config
153 | # NuGet v3's project.json files produces more ignoreable files
154 | *.nuget.props
155 | *.nuget.targets
156 |
157 | # Microsoft Azure Build Output
158 | csx/
159 | *.build.csdef
160 |
161 | # Microsoft Azure Emulator
162 | ecf/
163 | rcf/
164 |
165 | # Microsoft Azure ApplicationInsights config file
166 | ApplicationInsights.config
167 |
168 | # Windows Store app package directory
169 | AppPackages/
170 | BundleArtifacts/
171 |
172 | # Visual Studio cache files
173 | # files ending in .cache can be ignored
174 | *.[Cc]ache
175 | # but keep track of directories ending in .cache
176 | !*.[Cc]ache/
177 |
178 | # Others
179 | ClientBin/
180 | ~$*
181 | *~
182 | *.dbmdl
183 | *.dbproj.schemaview
184 | *.pfx
185 | *.publishsettings
186 | node_modules/
187 | orleans.codegen.cs
188 |
189 | # RIA/Silverlight projects
190 | Generated_Code/
191 |
192 | # Backup & report files from converting an old project file
193 | # to a newer Visual Studio version. Backup files are not needed,
194 | # because we have git ;-)
195 | _UpgradeReport_Files/
196 | Backup*/
197 | UpgradeLog*.XML
198 | UpgradeLog*.htm
199 |
200 | # SQL Server files
201 | *.mdf
202 | *.ldf
203 |
204 | # Business Intelligence projects
205 | *.rdl.data
206 | *.bim.layout
207 | *.bim_*.settings
208 |
209 | # Microsoft Fakes
210 | FakesAssemblies/
211 |
212 | # GhostDoc plugin setting file
213 | *.GhostDoc.xml
214 |
215 | # Node.js Tools for Visual Studio
216 | .ntvs_analysis.dat
217 |
218 | # Visual Studio 6 build log
219 | *.plg
220 |
221 | # Visual Studio 6 workspace options file
222 | *.opt
223 |
224 | # Visual Studio LightSwitch build output
225 | **/*.HTMLClient/GeneratedArtifacts
226 | **/*.DesktopClient/GeneratedArtifacts
227 | **/*.DesktopClient/ModelManifest.xml
228 | **/*.Server/GeneratedArtifacts
229 | **/*.Server/ModelManifest.xml
230 | _Pvt_Extensions
231 |
232 | # Paket dependency manager
233 | .paket/paket.exe
234 |
235 | # FAKE - F# Make
236 | .fake/
237 |
--------------------------------------------------------------------------------
/Build.ps1:
--------------------------------------------------------------------------------
1 | echo "build: Build started"
2 |
3 | Push-Location $PSScriptRoot
4 |
5 | if(Test-Path .\artifacts) {
6 | echo "build: Cleaning .\artifacts"
7 | Remove-Item .\artifacts -Force -Recurse
8 | }
9 |
10 | & dotnet restore --no-cache
11 |
12 | $branch = @{ $true = $env:APPVEYOR_REPO_BRANCH; $false = $(git symbolic-ref --short -q HEAD) }[$env:APPVEYOR_REPO_BRANCH -ne $NULL];
13 | $revision = @{ $true = "{0:00000}" -f [convert]::ToInt32("0" + $env:APPVEYOR_BUILD_NUMBER, 10); $false = "local" }[$env:APPVEYOR_BUILD_NUMBER -ne $NULL];
14 | $suffix = @{ $true = ""; $false = "$($branch.Substring(0, [math]::Min(10,$branch.Length)))-$revision"}[$branch -eq "master" -and $revision -ne "local"]
15 | $commitHash = $(git rev-parse --short HEAD)
16 | $buildSuffix = @{ $true = "$($suffix)-$($commitHash)"; $false = "$($branch)-$($commitHash)" }[$suffix -ne ""]
17 |
18 | echo "build: Package version suffix is $suffix"
19 | echo "build: Build version suffix is $buildSuffix"
20 |
21 | foreach ($src in ls src/*) {
22 | Push-Location $src
23 |
24 | echo "build: Packaging project in $src"
25 |
26 | & dotnet build -c Release --version-suffix=$buildSuffix
27 | & dotnet pack -c Release -o ..\..\artifacts --version-suffix=$suffix --no-build
28 | if($LASTEXITCODE -ne 0) { exit 1 }
29 |
30 | Pop-Location
31 | }
32 |
33 | foreach ($test in ls test/*.PerformanceTests) {
34 | Push-Location $test
35 |
36 | echo "build: Building performance test project in $test"
37 |
38 | & dotnet build -c Release
39 | if($LASTEXITCODE -ne 0) { exit 2 }
40 |
41 | Pop-Location
42 | }
43 |
44 | foreach ($test in ls test/*.Tests) {
45 | Push-Location $test
46 |
47 | echo "build: Testing project in $test"
48 |
49 | & dotnet test -c Release
50 | if($LASTEXITCODE -ne 0) { exit 3 }
51 |
52 | Pop-Location
53 | }
54 |
55 | Pop-Location
56 |
--------------------------------------------------------------------------------
/CHANGES.md:
--------------------------------------------------------------------------------
1 | 1.5
2 | * Moved from serilog/serilog
3 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright {yyyy} {name of copyright owner}
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
203 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Serilog.Sinks.NLog
2 |
3 | [](https://ci.appveyor.com/project/serilog/serilog-sinks-nlog/branch/master)
4 |
5 | Adapts Serilog to write events through existing NLog infrastructure.
6 |
7 | **Package** - [Serilog.Sinks.NLog](http://nuget.org/packages/serilog.sinks.nlog)
8 | | **Platforms** - .NET 4.5
9 |
10 | You'll need to configure NLog, too.
11 |
12 | ```csharp
13 | var log = new LoggerConfiguration()
14 | .WriteTo.NLog()
15 | .CreateLogger();
16 | ```
17 |
--------------------------------------------------------------------------------
/appveyor.yml:
--------------------------------------------------------------------------------
1 | version: '{build}'
2 | skip_tags: true
3 | image: Visual Studio 2015
4 | configuration: Release
5 | install:
6 | - ps: mkdir -Force ".\build\" | Out-Null
7 | - ps: Invoke-WebRequest "https://raw.githubusercontent.com/dotnet/cli/rel/1.0.0-preview2/scripts/obtain/dotnet-install.ps1" -OutFile ".\build\installcli.ps1"
8 | - ps: $env:DOTNET_INSTALL_DIR = "$pwd\.dotnetcli"
9 | - ps: '& .\build\installcli.ps1 -InstallDir "$env:DOTNET_INSTALL_DIR" -NoPath -Version 1.0.0-preview2-003121'
10 | - ps: $env:Path = "$env:DOTNET_INSTALL_DIR;$env:Path"
11 | build_script:
12 | - ps: ./Build.ps1
13 | test: off
14 | artifacts:
15 | - path: artifacts/Serilog.*.nupkg
16 | deploy:
17 | - provider: NuGet
18 | api_key:
19 | secure: nvZ/z+pMS91b3kG4DgfES5AcmwwGoBYQxr9kp4XiJHj25SAlgdIxFx++1N0lFH2x
20 | skip_symbols: true
21 | on:
22 | branch: /^(master|dev)$/
23 | - provider: GitHub
24 | auth_token:
25 | secure: p4LpVhBKxGS5WqucHxFQ5c7C8cP74kbNB0Z8k9Oxx/PMaDQ1+ibmoexNqVU5ZlmX
26 | artifact: /Serilog.*\.nupkg/
27 | tag: v$(appveyor_build_version)
28 | on:
29 | branch: master
30 |
--------------------------------------------------------------------------------
/assets/CommonAssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 |
3 | [assembly: AssemblyVersion("1.0.0.0")]
4 | [assembly: AssemblyFileVersion("1.1.1.1")]
5 | [assembly: AssemblyInformationalVersion("1.0.0")]
6 |
--------------------------------------------------------------------------------
/assets/Serilog.snk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/serilog-archive/serilog-sinks-nlog/65d948b98fdda2f68efdc7c4327b42d61cc38f99/assets/Serilog.snk
--------------------------------------------------------------------------------
/global.json:
--------------------------------------------------------------------------------
1 | {
2 | "projects": [ "src", "test" ],
3 | "sdk": {
4 | "version": "1.0.0-preview2-003121"
5 | }
6 | }
7 |
--------------------------------------------------------------------------------
/serilog-sinks-nlog.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 14
4 | VisualStudioVersion = 14.0.25420.1
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Serilog.Sinks.NLog", "src\Serilog.Sinks.NLog\Serilog.Sinks.NLog.xproj", "{BE40FF8E-7EEA-4094-90F0-CD67B061DCE4}"
7 | EndProject
8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{88A2B525-3326-4652-9BA4-A26227703B4C}"
9 | EndProject
10 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{DC682EBD-33E3-4ECF-922A-C022758E34E6}"
11 | EndProject
12 | Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Serilog.Sinks.NLog.Tests", "test\Serilog.Sinks.NLog.Tests\Serilog.Sinks.NLog.Tests.xproj", "{2C54FEB0-E282-40E8-90F4-0CDB4E7CB680}"
13 | EndProject
14 | Global
15 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
16 | Debug|Any CPU = Debug|Any CPU
17 | Release|Any CPU = Release|Any CPU
18 | EndGlobalSection
19 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
20 | {BE40FF8E-7EEA-4094-90F0-CD67B061DCE4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21 | {BE40FF8E-7EEA-4094-90F0-CD67B061DCE4}.Debug|Any CPU.Build.0 = Debug|Any CPU
22 | {BE40FF8E-7EEA-4094-90F0-CD67B061DCE4}.Release|Any CPU.ActiveCfg = Release|Any CPU
23 | {BE40FF8E-7EEA-4094-90F0-CD67B061DCE4}.Release|Any CPU.Build.0 = Release|Any CPU
24 | {2C54FEB0-E282-40E8-90F4-0CDB4E7CB680}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
25 | {2C54FEB0-E282-40E8-90F4-0CDB4E7CB680}.Debug|Any CPU.Build.0 = Debug|Any CPU
26 | {2C54FEB0-E282-40E8-90F4-0CDB4E7CB680}.Release|Any CPU.ActiveCfg = Release|Any CPU
27 | {2C54FEB0-E282-40E8-90F4-0CDB4E7CB680}.Release|Any CPU.Build.0 = Release|Any CPU
28 | EndGlobalSection
29 | GlobalSection(SolutionProperties) = preSolution
30 | HideSolutionNode = FALSE
31 | EndGlobalSection
32 | GlobalSection(NestedProjects) = preSolution
33 | {BE40FF8E-7EEA-4094-90F0-CD67B061DCE4} = {88A2B525-3326-4652-9BA4-A26227703B4C}
34 | {2C54FEB0-E282-40E8-90F4-0CDB4E7CB680} = {DC682EBD-33E3-4ECF-922A-C022758E34E6}
35 | EndGlobalSection
36 | EndGlobal
37 |
--------------------------------------------------------------------------------
/src/Serilog.Sinks.NLog/LoggerConfigurationsNLogExtensions.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2014 Serilog Contributors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | using System;
16 | using Serilog.Sinks.NLog;
17 | using Serilog.Configuration;
18 | using Serilog.Events;
19 | using Serilog.Formatting.Display;
20 |
21 | namespace Serilog
22 | {
23 | ///
24 | /// Adds the WriteTo.NLog() extension method to .
25 | ///
26 | public static class LoggerConfigurationsNLogExtensions
27 | {
28 | const string DefaultOutputTemplate = "{Message}";
29 |
30 | ///
31 | /// Adds a sink that writes adapted log events to NLog.
32 | ///
33 | /// The logger configuration.
34 | /// The minimum log event level required in order to write an event to the sink.
35 | /// Supplies culture-specific formatting information, or null.
36 | /// Logger configuration, allowing configuration to continue.
37 | /// A required parameter is null.
38 | public static LoggerConfiguration NLog(
39 | this LoggerSinkConfiguration loggerConfiguration,
40 | LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum,
41 | string outputTemplate = DefaultOutputTemplate,
42 | IFormatProvider formatProvider = null)
43 | {
44 | if (loggerConfiguration == null)
45 | {
46 | throw new ArgumentNullException(nameof(loggerConfiguration));
47 | }
48 |
49 | var formatter = new MessageTemplateTextFormatter(outputTemplate, formatProvider);
50 |
51 | return loggerConfiguration.Sink(new NLogSink(formatter), restrictedToMinimumLevel);
52 | }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/Serilog.Sinks.NLog/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 |
3 | [assembly: AssemblyTitle("Serilog.Sinks.NLog")]
4 | [assembly: AssemblyDescription("Serilog sink for NLog")]
5 | [assembly: AssemblyCopyright("Copyright © Serilog Contributors 2014")]
--------------------------------------------------------------------------------
/src/Serilog.Sinks.NLog/Serilog.Sinks.NLog.xproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 14.0
5 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)
6 |
7 |
8 |
9 | be40ff8e-7eea-4094-90f0-cd67b061dce4
10 | Serilog.Sinks.NLog
11 | .\obj
12 | .\bin\
13 |
14 |
15 |
16 | 2.0
17 |
18 |
19 |
--------------------------------------------------------------------------------
/src/Serilog.Sinks.NLog/Sinks/NLog/NLogSink.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using NLog;
3 | using Serilog.Core;
4 | using Serilog.Debugging;
5 | using Serilog.Events;
6 | using Serilog.Formatting;
7 | using System.IO;
8 |
9 | namespace Serilog.Sinks.NLog
10 | {
11 | class NLogSink : ILogEventSink
12 | {
13 | readonly ITextFormatter textFormatter;
14 |
15 | public NLogSink(ITextFormatter textFormatter)
16 | {
17 | this.textFormatter = textFormatter;
18 | }
19 |
20 | public void Emit(LogEvent logEvent)
21 | {
22 | var loggerName = "Default";
23 |
24 | LogEventPropertyValue sourceContext;
25 | if (logEvent.Properties.TryGetValue(Constants.SourceContextPropertyName, out sourceContext))
26 | {
27 | var sv = sourceContext as ScalarValue;
28 | if (sv != null && sv.Value is string)
29 | {
30 | loggerName = (string)sv.Value;
31 | }
32 | }
33 |
34 | var level = GetMappedLevel(logEvent);
35 |
36 | var renderSpace = new StringWriter();
37 | this.textFormatter.Format(logEvent, renderSpace);
38 |
39 | //var message = logEvent.RenderMessage(formatProvider);
40 | var exception = logEvent.Exception;
41 |
42 | var nlogEvent = new LogEventInfo(level, loggerName, renderSpace.ToString())
43 | {
44 | Exception = exception
45 | };
46 |
47 | // pass along the event's properties to nlog
48 | foreach (var property in logEvent.Properties)
49 | {
50 | // format simple scalar strings as literals (without wrapping quotes), which is more likely to be what nlog users expect
51 | var sv = property.Value as ScalarValue;
52 | var format = (sv != null && sv.Value is string) ? "l" : null;
53 |
54 | nlogEvent.Properties[property.Key] = property.Value.ToString(format, null);
55 | }
56 |
57 | var logger = LogManager.GetLogger(loggerName);
58 | logger.Log(nlogEvent);
59 | }
60 |
61 | private static LogLevel GetMappedLevel(LogEvent logEvent)
62 | {
63 | switch (logEvent.Level)
64 | {
65 | case LogEventLevel.Verbose:
66 | return LogLevel.Trace;
67 | case LogEventLevel.Debug:
68 | return LogLevel.Debug;
69 | case LogEventLevel.Information:
70 | return LogLevel.Info;
71 | case LogEventLevel.Warning:
72 | return LogLevel.Warn;
73 | case LogEventLevel.Error:
74 | return LogLevel.Error;
75 | case LogEventLevel.Fatal:
76 | return LogLevel.Fatal;
77 | default:
78 | SelfLog.WriteLine("Unexpected logging level, writing to NLog as Info");
79 | return LogLevel.Info;
80 | }
81 | }
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/src/Serilog.Sinks.NLog/project.json:
--------------------------------------------------------------------------------
1 | {
2 | "version": "3.0.1-*",
3 | "description": "Serilog event sink that writes to NLog. Merge your new Serilog event stream into your existing NLog infrastructure.",
4 | "authors": [ "Serilog Contributors" ],
5 | "packOptions": {
6 | "tags": [ "serilog", "logging", "NLog" ],
7 | "projectUrl": "http://serilog.net",
8 | "licenseUrl": "http://www.apache.org/licenses/LICENSE-2.0",
9 | "iconUrl": "http://serilog.net/images/serilog-sink-nuget.png"
10 | },
11 | "dependencies": {
12 | "NLog": "4.4.0-betaV15",
13 | "Serilog": "2.0.0"
14 | },
15 |
16 | "buildOptions": {
17 | "keyFile": "../../assets/Serilog.snk"
18 | },
19 | "frameworks": {
20 | "net45": {
21 | },
22 | "netstandard1.3": {
23 | "dependencies": {
24 | }
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/test/Serilog.Sinks.NLog.Tests/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | // Empty file just to generate the test assembly
2 |
--------------------------------------------------------------------------------
/test/Serilog.Sinks.NLog.Tests/Serilog.Sinks.NLog.Tests.xproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 14.0
5 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)
6 |
7 |
8 |
9 | 2c54feb0-e282-40e8-90f4-0cdb4e7cb680
10 | Serilog.Sinks.NLog.Tests
11 | .\obj
12 | .\bin\
13 |
14 |
15 | 2.0
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/test/Serilog.Sinks.NLog.Tests/Sinks/NLog/NLogSinkTest.cs:
--------------------------------------------------------------------------------
1 | using NLog;
2 | using NLog.Config;
3 | using NLog.Targets;
4 | using Serilog.Core;
5 | using System.Linq;
6 | using Xunit;
7 |
8 | namespace Serilog.Sinks.NLog.Tests.Sinks.NLog
9 | {
10 | public class NLogSinkTest
11 | {
12 | [Fact]
13 | public void LogsAreSentToNLog()
14 | {
15 | // Fixture setup
16 | SetupNLogConfiguration();
17 | // Exercise system
18 | var log = new LoggerConfiguration()
19 | .WriteTo.NLog()
20 | .CreateLogger();
21 | log.Warning("The quick brown fox jumps over the lazy dog");
22 | // Verify outcome
23 | var result = GetLastLoggedLineFromNLogMemotyTarget();
24 | Assert.Equal("Default|Warn|The quick brown fox jumps over the lazy dog", result);
25 | // Teardown
26 | TeardownNLogConfiguration();
27 | }
28 |
29 | [Fact]
30 | public void SourceContextIsUsedForNLogLogName()
31 | {
32 | // Fixture setup
33 | SetupNLogConfiguration();
34 | // Exercise system
35 | var log = new LoggerConfiguration()
36 | .Enrich.WithProperty(Constants.SourceContextPropertyName, "Test")
37 | .MinimumLevel.Verbose()
38 | .WriteTo.NLog()
39 | .CreateLogger();
40 | log.Debug("The quick brown fox jumps over the lazy dog");
41 | // Verify outcome
42 | var result = GetLastLoggedLineFromNLogMemotyTarget();
43 | Assert.Equal("Test|Debug|The quick brown fox jumps over the lazy dog", result);
44 | // Teardown
45 | TeardownNLogConfiguration();
46 | }
47 |
48 | [Fact]
49 | public void TestOutputTemplate()
50 | {
51 | // Fixture setup
52 | SetupNLogConfiguration();
53 | // Exercise system
54 | var log = new LoggerConfiguration()
55 | .WriteTo.NLog(outputTemplate: "[{Level}] - {Message}")
56 | .CreateLogger();
57 | log.Information("The quick brown fox jumps over the lazy dog");
58 | // Verify outcome
59 | var result = GetLastLoggedLineFromNLogMemotyTarget();
60 | Assert.Equal("Default|Info|[Information] - The quick brown fox jumps over the lazy dog", result);
61 | // Teardown
62 | TeardownNLogConfiguration();
63 | }
64 |
65 | private const string MemoryTargetName = "memory";
66 | private const string DefaultNLogLayout = @"${logger}|${level}|${message}";
67 |
68 | private void SetupNLogConfiguration()
69 | {
70 | var config = new LoggingConfiguration();
71 | var memoryTarget = new MemoryTarget();
72 | config.AddTarget(MemoryTargetName, memoryTarget);
73 | memoryTarget.Layout = DefaultNLogLayout;
74 | var rule = new LoggingRule("*", LogLevel.Trace, memoryTarget);
75 | config.LoggingRules.Add(rule);
76 | LogManager.Configuration = config;
77 | }
78 |
79 | private void TeardownNLogConfiguration()
80 | {
81 | LogManager.Configuration = null;
82 | }
83 |
84 | private string GetLastLoggedLineFromNLogMemotyTarget()
85 | {
86 | var target = (MemoryTarget)LogManager.Configuration.FindTargetByName(MemoryTargetName);
87 | return target.Logs.Last();
88 | }
89 | }
90 | }
91 |
--------------------------------------------------------------------------------
/test/Serilog.Sinks.NLog.Tests/project.json:
--------------------------------------------------------------------------------
1 | {
2 | "testRunner": "xunit",
3 | "dependencies": {
4 | "xunit": "2.2.0-beta2-build3300",
5 | "xunit.runner.visualstudio": "2.1.0",
6 | "dotnet-test-xunit": "2.2.0-preview2-build1029",
7 | "NLog": "4.4.0-betaV15",
8 | "Serilog.Sinks.NLog": { "target": "project" }
9 | },
10 | "frameworks": {
11 | "netcoreapp1.0": {
12 | "imports": "portable-net45+win8",
13 | "dependencies": {
14 | "Microsoft.NETCore.App": {
15 | "version": "1.0.0",
16 | "type": "platform"
17 | }
18 | }
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------