Skip to content

Commit b958c7f

Browse files
authored
Added serilog to hosting example
1 parent 63705b7 commit b958c7f

1 file changed

Lines changed: 18 additions & 3 deletions

File tree

README.md

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,13 +204,14 @@ let main argv =
204204
### Example using Microsoft.Extensions.Hosting
205205

206206
```F#
207+
open System
208+
open System.IO
209+
open FSharp.SystemCommandLine
207210
open Microsoft.Extensions.Hosting
208211
open Microsoft.Extensions.Logging
209212
open Microsoft.Extensions.Configuration
210213
open Microsoft.Extensions.DependencyInjection
211-
open FSharp.SystemCommandLine
212-
open System
213-
open System.IO
214+
open Serilog
214215
215216
let buildHost (argv: string[]) =
216217
Host.CreateDefaultBuilder(argv)
@@ -220,6 +221,20 @@ let buildHost (argv: string[]) =
220221
)
221222
.ConfigureLogging(fun logging ->
222223
logging.AddConsole() |> ignore
224+
logging.AddSerilog() |> ignore
225+
)
226+
.ConfigureServices(fun services ->
227+
// Serilog configuration
228+
let logger =
229+
LoggerConfiguration()
230+
.WriteTo.File(path = "logs/log.txt")
231+
.CreateLogger()
232+
233+
services.AddLogging(fun builder ->
234+
builder
235+
.SetMinimumLevel(LogLevel.Information)
236+
.AddSerilog(logger, dispose = true) |> ignore
237+
) |> ignore
223238
)
224239
.Build()
225240

0 commit comments

Comments
 (0)