├── .gitignore
├── LICENSE
├── README.md
├── console-sample
├── Dockerfile
└── src
│ ├── .dockerignore
│ ├── Program.cs
│ └── console-sample.csproj
├── docker-compose.yml
├── fsharp-kestrel-sample
├── Dockerfile
├── fsharp-kestrel-sample.sln
└── src
│ ├── .dockerignore
│ ├── Program.fs
│ ├── Properties
│ └── launchSettings.json
│ ├── Startup.fs
│ ├── appsettings.json
│ └── fsharp-kestrel-sample.fsproj
├── samples-windows.yml
├── samples.yml
├── serilog
├── Dockerfile
└── entry_point.sh
├── splunk
├── Dockerfile
└── etc
│ ├── apps
│ └── splunk_httpinput
│ │ └── local
│ │ └── inputs.conf
│ └── system
│ └── local
│ ├── inputs.conf
│ ├── server.conf
│ └── web.conf
├── sql
├── CREATE.sql
├── Dockerfile
├── entrypoint.sh
└── setup-logs.sh
└── web-sample
├── .dockerignore
├── Dockerfile
└── src
├── Program.cs
├── Startup.cs
├── appsettings.json
└── web-sample.csproj
/.gitignore:
--------------------------------------------------------------------------------
1 | # Created by https://www.gitignore.io/api/visualstudio
2 |
3 | ### VisualStudio ###
4 | ## Ignore Visual Studio temporary files, build results, and
5 | ## files generated by popular Visual Studio add-ons.
6 |
7 | # User-specific files
8 | *.suo
9 | *.user
10 | *.userosscache
11 | *.sln.docstates
12 |
13 | # User-specific files (MonoDevelop/Xamarin Studio)
14 | *.userprefs
15 |
16 | # Build results
17 | [Dd]ebug/
18 | [Dd]ebugPublic/
19 | [Rr]elease/
20 | [Rr]eleases/
21 | x64/
22 | x86/
23 | build/
24 | bld/
25 | [Bb]in/
26 | [Oo]bj/
27 |
28 | # Visual Studio 2015 cache/options directory
29 | .vs/
30 | # Uncomment if you have tasks that create the project's static files in wwwroot
31 | #wwwroot/
32 |
33 | # MSTest test Results
34 | [Tt]est[Rr]esult*/
35 | [Bb]uild[Ll]og.*
36 |
37 | # NUNIT
38 | *.VisualState.xml
39 | TestResult.xml
40 |
41 | # Build Results of an ATL Project
42 | [Dd]ebugPS/
43 | [Rr]eleasePS/
44 | dlldata.c
45 |
46 | # DNX
47 | project.lock.json
48 | artifacts/
49 |
50 | *_i.c
51 | *_p.c
52 | *_i.h
53 | *.ilk
54 | *.meta
55 | *.obj
56 | *.pch
57 | *.pdb
58 | *.pgc
59 | *.pgd
60 | *.rsp
61 | *.sbr
62 | *.tlb
63 | *.tli
64 | *.tlh
65 | *.tmp
66 | *.tmp_proj
67 | *.log
68 | *.vspscc
69 | *.vssscc
70 | .builds
71 | *.pidb
72 | *.svclog
73 | *.scc
74 |
75 | # Chutzpah Test files
76 | _Chutzpah*
77 |
78 | # Visual C++ cache files
79 | ipch/
80 | *.aps
81 | *.ncb
82 | *.opensdf
83 | *.sdf
84 | *.cachefile
85 |
86 | # Visual Studio profiler
87 | *.psess
88 | *.vsp
89 | *.vspx
90 |
91 | # TFS 2012 Local Workspace
92 | $tf/
93 |
94 | # Guidance Automation Toolkit
95 | *.gpState
96 |
97 | # ReSharper is a .NET coding add-in
98 | _ReSharper*/
99 | *.[Rr]e[Ss]harper
100 | *.DotSettings.user
101 |
102 | # JustCode is a .NET coding add-in
103 | .JustCode
104 |
105 | # TeamCity is a build add-in
106 | _TeamCity*
107 |
108 | # DotCover is a Code Coverage Tool
109 | *.dotCover
110 |
111 | # NCrunch
112 | _NCrunch_*
113 | .*crunch*.local.xml
114 | nCrunchTemp_*
115 |
116 | # MightyMoose
117 | *.mm.*
118 | AutoTest.Net/
119 |
120 | # Web workbench (sass)
121 | .sass-cache/
122 |
123 | # Installshield output folder
124 | [Ee]xpress/
125 |
126 | # DocProject is a documentation generator add-in
127 | DocProject/buildhelp/
128 | DocProject/Help/*.HxT
129 | DocProject/Help/*.HxC
130 | DocProject/Help/*.hhc
131 | DocProject/Help/*.hhk
132 | DocProject/Help/*.hhp
133 | DocProject/Help/Html2
134 | DocProject/Help/html
135 |
136 | # Click-Once directory
137 | publish/
138 |
139 | # Publish Web Output
140 | *.[Pp]ublish.xml
141 | *.azurePubxml
142 | # TODO: Comment the next line if you want to checkin your web deploy settings
143 | # but database connection strings (with potential passwords) will be unencrypted
144 | *.pubxml
145 | *.publishproj
146 |
147 | # NuGet Packages
148 | *.nupkg
149 | # The packages folder can be ignored because of Package Restore
150 | **/packages/*
151 | # except build/, which is used as an MSBuild target.
152 | !**/packages/build/
153 | # Uncomment if necessary however generally it will be regenerated when needed
154 | #!**/packages/repositories.config
155 |
156 | # Windows Azure Build Output
157 | csx/
158 | *.build.csdef
159 |
160 | # Windows Store app package directory
161 | AppPackages/
162 |
163 | # Visual Studio cache files
164 | # files ending in .cache can be ignored
165 | *.[Cc]ache
166 | # but keep track of directories ending in .cache
167 | !*.[Cc]ache/
168 |
169 | # Others
170 | ClientBin/
171 | [Ss]tyle[Cc]op.*
172 | ~$*
173 | *~
174 | *.dbmdl
175 | *.dbproj.schemaview
176 | *.pfx
177 | *.publishsettings
178 | node_modules/
179 | orleans.codegen.cs
180 |
181 | # RIA/Silverlight projects
182 | Generated_Code/
183 |
184 | # Backup & report files from converting an old project file
185 | # to a newer Visual Studio version. Backup files are not needed,
186 | # because we have git ;-)
187 | _UpgradeReport_Files/
188 | Backup*/
189 | UpgradeLog*.XML
190 | UpgradeLog*.htm
191 |
192 | # SQL Server files
193 | *.mdf
194 | *.ldf
195 |
196 | # Business Intelligence projects
197 | *.rdl.data
198 | *.bim.layout
199 | *.bim_*.settings
200 |
201 | # Microsoft Fakes
202 | FakesAssemblies/
203 |
204 | # Node.js Tools for Visual Studio
205 | .ntvs_analysis.dat
206 |
207 | # Visual Studio 6 build log
208 | *.plg
209 |
210 | # Visual Studio 6 workspace options file
211 | *.opt
212 |
213 | # Visual Studio LightSwitch build output
214 | **/*.HTMLClient/GeneratedArtifacts
215 | **/*.DesktopClient/GeneratedArtifacts
216 | **/*.DesktopClient/ModelManifest.xml
217 | **/*.Server/GeneratedArtifacts
218 | **/*.Server/ModelManifest.xml
219 | _Pvt_Extensions
220 | *.orig
221 |
222 | .vscode
223 |
224 | web-sample/src/out/
225 | console-sample/src/out/
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Serilog with Docker
2 | A docker image for testing Serilog on Docker platforms. It also includes a number of sample apps.
3 |
4 | ## PreReqs
5 |
6 | * Docker
7 |
8 | # Building the Serilog Library
9 | - Clone this repo.
10 | - Run `docker-compose build` to:
11 | + pull the images
12 | + build a docker image
13 | - Run `docker-compose up` to:
14 | * pull the Serilog repo,
15 | * build and test the lastest `dev` branch code from https://github.com/serilog/serilog.
16 | - To enter the container with out using compose, use `docker run -it --entrypoint=/bin/bash serilog`
17 |
18 |
19 | # Run the Samples
20 |
21 | This repo also contains the following samples:
22 |
23 | * Console App
24 | * Web App
25 | * FSharp Web App
26 |
27 | To run these, run `docker-compose -f samples.yml up --build`
28 |
29 | This will
30 |
31 | * Build & run the sample docker images.
32 | * The console app periodically does a HTTP GET to the
33 | * `C#` Kestrel Sample
34 | * `F#` Kestrel Sample
35 | * The console app also logs to the [Console](https://github.com/serilog/serilog-sinks-console), [Seq](https://github.com/serilog/serilog-sinks-seq) and [Splunk](https://github.com/serilog/serilog-sinks-splunk) sinks.
36 | * The web apps are also configured to use Serilog via `Microsoft.Extensions.Logging` & `Serilog.Extensions.Logging`.
37 |
38 | * Seq Host - http://localhost:80
39 | * Splunk Host - http://localhost:8000
40 |
41 |
42 | # Windows Containers samples
43 |
44 | ## PreReqs
45 |
46 | * Windows Server 2016 ([evaluate](https://www.microsoft.com/en-us/evalcenter/evaluate-windows-server-2016))
47 | * Enable containers feature. See [MSDN documentation](https://msdn.microsoft.com/virtualization/windowscontainers/containers_welcome) for more details.
48 | * Docker tools
49 |
50 | ### Quick setup
51 | ```powershell
52 | # Add the containers feature and restart
53 | Install-WindowsFeature containers
54 | Restart-Computer -Force
55 |
56 | # Download, install Docker Engine, Docker Compose
57 | Invoke-WebRequest "https://download.docker.com/components/engine/windows-server/cs-1.12/docker.zip" -OutFile "$env:TEMP\docker.zip" -UseBasicParsing
58 | Expand-Archive -Path "$env:TEMP\docker.zip" -DestinationPath $env:ProgramFiles
59 |
60 | Invoke-WebRequest -Uri https://dl.bintray.com/docker-compose/master/docker-compose-Windows-x86_64.exe -OutFile $env:ProgramFiles\Docker\docker-compose.exe -UseBasicParsing
61 |
62 | # set PATH
63 | $env:Path += ";c:\program files\docker"
64 | [Environment]::SetEnvironmentVariable("Path", $env:Path + ";C:\Program Files\Docker", [EnvironmentVariableTarget]::Machine)
65 |
66 | # Configure Docker daemon to listen on both pipe and TCP
67 | dockerd.exe -H npipe:////./pipe/docker_engine -H 0.0.0.0:2375 --register-service
68 |
69 | # Start Docker daemon
70 | Start-Service docker
71 | ```
72 |
73 | ## Run the Samples
74 |
75 | This repo contains the following windows samples
76 |
77 | * Seq Event Server, based on [Windows Server 2016 Server Core](https://hub.docker.com/r/microsoft/windowsservercore/) image
78 | * Web App, based on [Windows Server 2016 Nano Server](https://hub.docker.com/r/microsoft/nanoserver/) image
79 |
80 | To run these, run `docker-compose -f samples-windows.yml up`
81 |
82 | Containers use `nat` network. To inspect what IPs they got run `docker network inspect nat` in the separate cmd shell and find your containers:
83 | ```cmd
84 | "Containers": {
85 | "5f66928248090245cc4313d8ff114a27e2a98ffaaf25f77518e6b7b8eb042c3a": {
86 | "Name": "serilogdocker_web-sample_1",
87 | "EndpointID": "1b18aae7a2bb05e3b82e7bd35a63595a7aef828041e77c4da61c6ca36537ed5e",
88 | "IPv4Address": "172.23.144.124/16",
89 | "IPv6Address": ""
90 | },
91 | "83313f0f78ca0447801ef29d1953e65be3d73e1d168c627e5593a255eedd1672": {
92 | "Name": "serilogdocker_seq_1",
93 | "EndpointID": "6649b52db115b5f7288e4a99fa298b7fe4f1991892abdbed9305cb175143e775",
94 | "IPv4Address": "172.23.155.24/16",
95 | "IPv6Address": ""
96 | }
97 | }
98 | ```
99 |
100 | Navigate to the Web App and Seq Web UI (`http://172.23.144.124:5000` and `http://172.23.155.24:5341/` accordingly for the example above)
--------------------------------------------------------------------------------
/console-sample/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM microsoft/dotnet:2.0-sdk AS build
2 | WORKDIR /sample
3 | ADD src /sample
4 | RUN dotnet restore
5 | RUN dotnet publish -c Release -o out
6 |
7 | FROM microsoft/dotnet:2.0-runtime AS runtime
8 | WORKDIR /sample
9 | COPY --from=build /sample/out ./
10 | ENTRYPOINT ["dotnet", "console-sample.dll"]
--------------------------------------------------------------------------------
/console-sample/src/.dockerignore:
--------------------------------------------------------------------------------
1 | bin\
2 | obj\
--------------------------------------------------------------------------------
/console-sample/src/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Serilog;
3 | using System.Threading.Tasks;
4 | using System.Net;
5 | using System.Net.Http;
6 |
7 | namespace Sample
8 | {
9 | public static class Program
10 | {
11 | public static void Main(string[] args)
12 | {
13 | Serilog.Debugging.SelfLog.Enable(Console.Error);
14 |
15 |
16 | var connectionString = @"Server=sql;Database=Serilog;User=sa;Password=test1234****;";
17 |
18 | Log.Logger = new LoggerConfiguration()
19 | .MinimumLevel.Debug()
20 | .WriteTo.Console()
21 | .WriteTo.Seq("http://seq:5341/")
22 | .WriteTo.EventCollector("http://splunk:8088/","00112233-4455-6677-8899-AABBCCDDEEFF")
23 | .WriteTo.MSSqlServer(connectionString, "Logs", autoCreateSqlTable: true)
24 | .Enrich.WithProperty("App Name", "Serilog Console Docker Sample")
25 | .CreateLogger();
26 |
27 | Log.Information("Starting Serilog Console Sample");
28 |
29 | Go(Log.Logger).Wait();
30 |
31 | }
32 |
33 | private static async Task Go(ILogger logger)
34 | {
35 | while (true)
36 | {
37 | logger.Information("Serilog Console checking Web Sample at http://websample:5000");
38 |
39 | try
40 | {
41 | using (var client = new HttpClient())
42 | using (var response = await client.GetAsync("http://websample:5000"))
43 | using (var content = response.Content)
44 | {
45 | string result = await content.ReadAsStringAsync();
46 | logger.Information(result);
47 | }
48 | }
49 | catch (System.Exception ex)
50 | {
51 | logger.Error(ex, "An error occured for HTTP GET to http://websample:5000");
52 | }
53 |
54 | logger.Information("Serilog Console checking F# Web Sample at http://fswebsample:5001");
55 | try
56 | {
57 | using (var client = new HttpClient())
58 | using (var response = await client.GetAsync("http://fswebsample:5001"))
59 | using (var content = response.Content)
60 | {
61 | string result = await content.ReadAsStringAsync();
62 | logger.Information(result);
63 | }
64 | }
65 | catch (System.Exception ex)
66 | {
67 | logger.Error(ex, "An error occured for HTTP GET to http://fswebsample:5001");
68 | }
69 |
70 | await Task.Delay(3000);
71 | }
72 | }
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/console-sample/src/console-sample.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netcoreapp2.0
5 | Exe
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/docker-compose.yml:
--------------------------------------------------------------------------------
1 | version: '2'
2 |
3 | services:
4 | serilog:
5 | build: ./serilog
6 | image: serilog
--------------------------------------------------------------------------------
/fsharp-kestrel-sample/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM microsoft/dotnet:2.0-sdk AS build
2 | # FROM microsoft/aspnetcore:2.0.0 AS build
3 | WORKDIR /sample
4 | ADD src /sample
5 | RUN dotnet restore
6 | RUN dotnet publish -c Release -o out
7 |
8 | FROM microsoft/dotnet:2.0-runtime AS runtime
9 | ENV ASPNETCORE_URLS http://*:5001
10 | WORKDIR /sample
11 | COPY --from=build /sample/out ./
12 | ENTRYPOINT ["dotnet", "fsharp-kestrel-sample.dll"]
13 |
--------------------------------------------------------------------------------
/fsharp-kestrel-sample/fsharp-kestrel-sample.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 15
4 | VisualStudioVersion = 15.0.26124.0
5 | MinimumVisualStudioVersion = 15.0.26124.0
6 | Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "fsharp-kestrel-sample", "src\fsharp-kestrel-sample.fsproj", "{7732985C-A4AE-489A-BBFD-BF4E0FBD4CCE}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|Any CPU = Debug|Any CPU
11 | Debug|x64 = Debug|x64
12 | Debug|x86 = Debug|x86
13 | Release|Any CPU = Release|Any CPU
14 | Release|x64 = Release|x64
15 | Release|x86 = Release|x86
16 | EndGlobalSection
17 | GlobalSection(SolutionProperties) = preSolution
18 | HideSolutionNode = FALSE
19 | EndGlobalSection
20 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
21 | {7732985C-A4AE-489A-BBFD-BF4E0FBD4CCE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
22 | {7732985C-A4AE-489A-BBFD-BF4E0FBD4CCE}.Debug|Any CPU.Build.0 = Debug|Any CPU
23 | {7732985C-A4AE-489A-BBFD-BF4E0FBD4CCE}.Debug|x64.ActiveCfg = Debug|Any CPU
24 | {7732985C-A4AE-489A-BBFD-BF4E0FBD4CCE}.Debug|x64.Build.0 = Debug|Any CPU
25 | {7732985C-A4AE-489A-BBFD-BF4E0FBD4CCE}.Debug|x86.ActiveCfg = Debug|Any CPU
26 | {7732985C-A4AE-489A-BBFD-BF4E0FBD4CCE}.Debug|x86.Build.0 = Debug|Any CPU
27 | {7732985C-A4AE-489A-BBFD-BF4E0FBD4CCE}.Release|Any CPU.ActiveCfg = Release|Any CPU
28 | {7732985C-A4AE-489A-BBFD-BF4E0FBD4CCE}.Release|Any CPU.Build.0 = Release|Any CPU
29 | {7732985C-A4AE-489A-BBFD-BF4E0FBD4CCE}.Release|x64.ActiveCfg = Release|Any CPU
30 | {7732985C-A4AE-489A-BBFD-BF4E0FBD4CCE}.Release|x64.Build.0 = Release|Any CPU
31 | {7732985C-A4AE-489A-BBFD-BF4E0FBD4CCE}.Release|x86.ActiveCfg = Release|Any CPU
32 | {7732985C-A4AE-489A-BBFD-BF4E0FBD4CCE}.Release|x86.Build.0 = Release|Any CPU
33 | EndGlobalSection
34 | EndGlobal
35 |
--------------------------------------------------------------------------------
/fsharp-kestrel-sample/src/.dockerignore:
--------------------------------------------------------------------------------
1 | bin\
2 | obj\
--------------------------------------------------------------------------------
/fsharp-kestrel-sample/src/Program.fs:
--------------------------------------------------------------------------------
1 | namespace FSharpKestrelSample
2 |
3 | open System.IO
4 | open Microsoft.AspNetCore
5 | open Microsoft.AspNetCore.Hosting
6 | open Microsoft.Extensions.Configuration
7 | open Serilog
8 |
9 | module Program =
10 | let successExitCode = 0
11 | let failureExitCode = 1
12 |
13 | let Configuration =
14 | ConfigurationBuilder()
15 | .SetBasePath(Directory.GetCurrentDirectory())
16 | .AddJsonFile("appsettings.json", optional=true, reloadOnChange=true)
17 | .Build() :> IConfiguration
18 |
19 | let CreateWebHostBuilder args =
20 | WebHost
21 | .CreateDefaultBuilder(args)
22 | .UseSerilog()
23 | .UseStartup();
24 |
25 | []
26 | let main args =
27 |
28 | Log.Logger <- LoggerConfiguration()
29 | .ReadFrom.Configuration(Configuration)
30 | .Enrich.WithProperty("App Name", "Serilog F# Kestrel Sample")
31 | .CreateLogger()
32 |
33 | Log.Information("Starting with arguments {Args}", args)
34 |
35 | try
36 | try
37 | CreateWebHostBuilder(args).Build().Run()
38 | successExitCode
39 | with
40 | | ex ->
41 | Log.Fatal(ex, "Host terminated unexpectedly")
42 | failureExitCode
43 | finally
44 | Log.Information("Shutting down")
45 | Log.CloseAndFlush()
46 |
--------------------------------------------------------------------------------
/fsharp-kestrel-sample/src/Properties/launchSettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "iisSettings": {
3 | "windowsAuthentication": false,
4 | "anonymousAuthentication": true,
5 | "iisExpress": {
6 | "applicationUrl": "http://localhost:33649",
7 | "sslPort": 44389
8 | }
9 | },
10 | "profiles": {
11 | "IIS Express": {
12 | "commandName": "IISExpress",
13 | "launchBrowser": true,
14 | "environmentVariables": {
15 | "ASPNETCORE_ENVIRONMENT": "Development"
16 | }
17 | },
18 | "fsharp-kestrel-sample": {
19 | "commandName": "Project",
20 | "launchBrowser": true,
21 | "applicationUrl": "https://localhost:5002;http://localhost:5003",
22 | "environmentVariables": {
23 | "ASPNETCORE_ENVIRONMENT": "Development"
24 | }
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/fsharp-kestrel-sample/src/Startup.fs:
--------------------------------------------------------------------------------
1 | namespace FSharpKestrelSample
2 |
3 | open Microsoft.AspNetCore.Builder
4 | open Microsoft.AspNetCore.Hosting
5 | open Microsoft.AspNetCore.Http
6 | open Microsoft.Extensions.DependencyInjection
7 |
8 | type Startup() =
9 |
10 | // This method gets called by the runtime. Use this method to add services to the container.
11 | // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
12 | member this.ConfigureServices(services: IServiceCollection) =
13 | ()
14 |
15 | // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
16 | member this.Configure(app: IApplicationBuilder, env: IHostingEnvironment) =
17 | if env.IsDevelopment() then
18 | app.UseDeveloperExceptionPage() |> ignore
19 |
20 | let responseContent = "In F#, the world hellos you!"
21 | app.Run(fun context -> context.Response.WriteAsync(responseContent)) |> ignore
22 |
--------------------------------------------------------------------------------
/fsharp-kestrel-sample/src/appsettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "Serilog": {
3 | "MinimumLevel": {
4 | "Default": "Debug",
5 | "Override": {
6 | "System": "Information",
7 | "Microsoft": "Information"
8 | }
9 | },
10 | "Using": ["Serilog.Sinks.Console", "Serilog.Sinks.Seq"],
11 | "WriteTo": [
12 | { "Name": "Console" },
13 | {
14 | "Name": "Seq",
15 | "Args": {
16 | "serverUrl": "http://seq:5341/",
17 | "compact": true
18 | }
19 | }
20 | ],
21 | "Enrich": ["FromLogContext"]
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/fsharp-kestrel-sample/src/fsharp-kestrel-sample.fsproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netcoreapp2.0
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 | false
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/samples-windows.yml:
--------------------------------------------------------------------------------
1 | version: '2'
2 |
3 | services:
4 | seq:
5 | build: ./seq
6 | image: serilog-seq-server
7 | ports:
8 | - 5341:5341
9 | tty: true
10 | web-sample:
11 | build: ./web-sample/src
12 | image: serilog-web-sample
13 | environment:
14 | Serilog__WriteTo__1__Args__serverUrl: http://seq:5341/
15 | depends_on:
16 | - "seq"
17 | ports:
18 | - 5000:5000
19 | tty: true
20 |
21 | networks:
22 | default:
23 | external:
24 | name: nat
--------------------------------------------------------------------------------
/samples.yml:
--------------------------------------------------------------------------------
1 | version: '2'
2 |
3 | services:
4 | consoleapp:
5 | build: ./console-sample
6 | image: serilog-console-sample
7 | websample:
8 | build: ./web-sample
9 | image: serilog-web-sample
10 | ports:
11 | - 5000:5000
12 | depends_on:
13 | - "seq"
14 | - "sql"
15 | fswebsample:
16 | build: ./fsharp-kestrel-sample
17 | image: serilog-fsharp-kestrel-sample
18 | ports:
19 | - 5001:5001
20 | splunk:
21 | build: ./splunk
22 | image: serilog-splunk
23 | ports:
24 | - 8000:8000
25 | - 8088:8088
26 | - 8089:8089
27 | environment:
28 | SPLUNK_START_ARGS: "--accept-license --answer-yes"
29 | SPLUNK_USER: "root"
30 | seq:
31 | image: datalust/seq
32 | environment:
33 | ACCEPT_EULA: "Y"
34 | ports:
35 | - 5341:5341
36 | - 80:80
37 | sql:
38 | build: ./sql
39 | environment:
40 | ACCEPT_EULA: "Y"
41 | MSSQL_SA_PASSWORD: "test1234****"
42 | ports:
43 | - 1433:1433
--------------------------------------------------------------------------------
/serilog/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM microsoft/dotnet:2.0-sdk
2 |
3 | #Dependencies
4 | ENV SERILOG_BRANCH dev
5 | ENV SERILOG_REPO https://github.com/serilog/serilog.git
6 |
7 | # Get Git and Friends
8 | RUN apt-get update \
9 | && apt-get install -y wget curl git \
10 | && apt-get -y autoremove \
11 | && apt-get -y clean \
12 | && rm -rf /var/lib/apt/lists/*
13 |
14 | COPY entry_point.sh entry_point.sh
15 | RUN chmod +x /entry_point.sh
16 |
17 | ENTRYPOINT ["/entry_point.sh"]
18 |
--------------------------------------------------------------------------------
/serilog/entry_point.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | rm -r -f serilog/
3 | set -e
4 | git clone -b $SERILOG_BRANCH $SERILOG_REPO --depth=1
5 | cd serilog/
6 |
7 | ulimit -n 2048
8 |
9 | sh build.sh
--------------------------------------------------------------------------------
/splunk/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM splunk/splunk:6.5.3
2 | ADD etc ${SPLUNK_HOME}/etc
--------------------------------------------------------------------------------
/splunk/etc/apps/splunk_httpinput/local/inputs.conf:
--------------------------------------------------------------------------------
1 | [http]
2 | disabled = 0
3 | enableSSL = 0
4 |
5 | [http://serilog_sample]
6 | token = 00112233-4455-6677-8899-AABBCCDDEEFF
--------------------------------------------------------------------------------
/splunk/etc/system/local/inputs.conf:
--------------------------------------------------------------------------------
1 | [http]
2 | disabled = 0
3 | useDeploymentServer = 0
--------------------------------------------------------------------------------
/splunk/etc/system/local/server.conf:
--------------------------------------------------------------------------------
1 | [general]
2 | allowRemoteLogin = always
3 |
4 | [diskUsage]
5 | minFreeSpace = 0
--------------------------------------------------------------------------------
/splunk/etc/system/local/web.conf:
--------------------------------------------------------------------------------
1 | [settings]
2 | enable_insecure_login = True
--------------------------------------------------------------------------------
/sql/CREATE.sql:
--------------------------------------------------------------------------------
1 | CREATE DATABASE Serilog
2 | GO
3 | USE Serilog
4 | GO
5 | CREATE TABLE [Logs] (
6 | [Id] int IDENTITY(1,1) NOT NULL,
7 | [Message] nvarchar(max) NULL,
8 | [MessageTemplate] nvarchar(max) NULL,
9 | [Level] nvarchar(128) NULL,
10 | [TimeStamp] datetimeoffset(7) NOT NULL,
11 | [Exception] nvarchar(max) NULL,
12 | [Properties] xml NULL,
13 | [LogEvent] nvarchar(max) NULL
14 | )
--------------------------------------------------------------------------------
/sql/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM microsoft/mssql-server-linux:2017-latest
2 |
3 | # Create app directory
4 | RUN mkdir -p /usr/src/
5 | WORKDIR /usr/src/
6 | COPY . /usr/src/
7 | RUN chmod +x /usr/src/setup-logs.sh
8 | CMD /bin/bash ./entrypoint.sh
--------------------------------------------------------------------------------
/sql/entrypoint.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | /opt/mssql/bin/sqlservr & /usr/src/setup-logs.sh
--------------------------------------------------------------------------------
/sql/setup-logs.sh:
--------------------------------------------------------------------------------
1 | #wait for the SQL Server to come up
2 | sleep 15s
3 | /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P "test1234****" -d master -i CREATE.sql
4 | # Hack to keep script running
5 | while :; do echo 'SLEEP'; sleep 20000; done
--------------------------------------------------------------------------------
/web-sample/.dockerignore:
--------------------------------------------------------------------------------
1 | bin\
2 | obj\
--------------------------------------------------------------------------------
/web-sample/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM microsoft/dotnet:2.0-sdk AS build
2 | # FROM microsoft/aspnetcore:2.0.0 AS build
3 | WORKDIR /sample
4 | ADD src /sample
5 | RUN dotnet restore
6 | RUN dotnet publish -c Release -o out
7 |
8 | FROM microsoft/dotnet:2.0-runtime AS runtime
9 | ENV ASPNETCORE_URLS http://*:5000
10 | WORKDIR /sample
11 | COPY --from=build /sample/out ./
12 | ENTRYPOINT ["dotnet", "web-sample.dll"]
--------------------------------------------------------------------------------
/web-sample/src/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Linq;
5 | using System.Threading.Tasks;
6 | using Microsoft.AspNetCore;
7 | using Microsoft.AspNetCore.Hosting;
8 | using Microsoft.Extensions.Configuration;
9 | using Microsoft.Extensions.Logging;
10 | using Serilog.Events;
11 | using Serilog.Core;
12 | using Serilog;
13 |
14 | namespace aspnetcoreapp
15 | {
16 | public class Program
17 | {
18 | public static IConfiguration Configuration { get; } = new ConfigurationBuilder()
19 | .SetBasePath(Directory.GetCurrentDirectory())
20 | .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
21 | .AddEnvironmentVariables()
22 | .Build();
23 |
24 | public static IWebHost BuildWebHost(string[] args) =>
25 | WebHost.CreateDefaultBuilder(args)
26 | .UseStartup()
27 | .UseSerilog()
28 | .UseKestrel()
29 | .Build();
30 |
31 | public static void Main(string[] args)
32 | {
33 | Log.Logger = new LoggerConfiguration()
34 | .ReadFrom.Configuration(Configuration)
35 | .Enrich.WithProperty("App Name", "Serilog Web App Sample")
36 | .CreateLogger();
37 | try
38 | {
39 | BuildWebHost(args).Run();
40 | return;
41 | }
42 | catch (Exception ex)
43 | {
44 | Log.Fatal(ex, "Host terminated unexpectedly");
45 | return;
46 | }
47 | finally
48 | {
49 | Log.CloseAndFlush();
50 | }
51 | }
52 | }
53 | }
--------------------------------------------------------------------------------
/web-sample/src/Startup.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Threading.Tasks;
5 | using Microsoft.AspNetCore.Builder;
6 | using Microsoft.AspNetCore.Hosting;
7 | using Microsoft.AspNetCore.Http;
8 |
9 | using Microsoft.Extensions.Configuration;
10 | using Microsoft.Extensions.DependencyInjection;
11 | using Microsoft.Extensions.Logging;
12 | using Microsoft.Extensions.Options;
13 |
14 | namespace aspnetcoreapp
15 | {
16 | public class Startup
17 | {
18 | public Startup(IConfiguration configuration)
19 | {
20 | Configuration = configuration;
21 | }
22 |
23 | public IConfiguration Configuration { get; }
24 |
25 | public void ConfigureServices(IServiceCollection services)
26 | {
27 | services.AddMvc();
28 | }
29 |
30 | public void Configure(IApplicationBuilder app, IHostingEnvironment env)
31 | {
32 | app.Run(async context =>
33 | {
34 | await context.Response.WriteAsync("Hello, World!");
35 | });
36 | }
37 | }
38 | }
--------------------------------------------------------------------------------
/web-sample/src/appsettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "Serilog": {
3 | "MinimumLevel": {
4 | "Default": "Debug",
5 | "Override": {
6 | "System": "Information",
7 | "Microsoft": "Information"
8 | }
9 | },
10 | "WriteTo": [
11 | { "Name": "Console" },
12 | {
13 | "Name": "Seq",
14 | "Args": {
15 | "serverUrl": "http://seq:5341/",
16 | "compact": true
17 | }
18 | }
19 | ],
20 | "Enrich": ["FromLogContext"]
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/web-sample/src/web-sample.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netcoreapp2.0
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 | false
19 |
20 |
21 |
--------------------------------------------------------------------------------