I am new to c# and I am trying to using serilog in a WCF application. This WCF application is hosted on IIS 6.0.
I need to create the logger once only when the service is initialized. However WCF does not seem to have constructors. How can I create the logger below once only and have it available to the rest of the application. Any code examples would be greatly appreciated.
ILogger logger = new LoggerConfiguration()
.ReadAppSettings()
.CreateLogger();
Log.Logger = logger;
I thought about using the AppInitialize in the App_Code folder but I cannot seem to get the program to trigger the AppInitialize method.
public class InitializeApp
{
public static void AppInitialize()
{
ILogger logger = new LoggerConfiguration()
.ReadAppSettings()
.CreateLogger();
Log.Logger = logger;
}
}
When I run the project in Visual Studio 2019 AppInitialize never gets hit.