File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
207210open Microsoft.Extensions.Hosting
208211open Microsoft.Extensions.Logging
209212open Microsoft.Extensions.Configuration
210213open Microsoft.Extensions.DependencyInjection
211- open FSharp.SystemCommandLine
212- open System
213- open System.IO
214+ open Serilog
214215
215216let 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
You can’t perform that action at this time.
0 commit comments