How to add logging.AddEventSourceLogger() in F#

152 Views Asked by At

I need to do an Azure .NET Profiler Trace on my .NET Core 2.1.1 web app.

Azure provides the following instructions on how to do this:

Ensure that you have the below code in your app's Program.cs as mentioned in Logging in ASP.NET Core article.

logging.AddEventSourceLogger();

Update the default LogLevel in appsettings.json to Information, like below

"Logging": { LogLevel": { Default": "Information" } }

However, there are no instructions for F#.

How can I add logging.AddEventSourceLogger(); to my Program.fs file?

open Microsoft.AspNetCore
open Microsoft.AspNetCore.Hosting

module Program =
let exitCode = 0

let CreateWebHostBuilder args =
    WebHost
        .CreateDefaultBuilder(args)
        .UseStartup<Startup>();

[<EntryPoint>]
let main args =
    CreateWebHostBuilder(args).Build().Run()

    exitCode
1

There are 1 best solutions below

0
Maku On BEST ANSWER

You can add event source logger in ConfigureLogging extension method of IWebHostBuilder:

let CreateWebHostBuilder args =
    WebHost
        .CreateDefaultBuilder(args)
        .ConfigureLogging(fun logging ->
            logging.AddEventSourceLogger() |> ignore
        )
        .UseStartup<Startup>(); 

Related Questions in F#