How to initialize the Serilog logger in a WCF service

Hello,
I am new to c# and I am trying to using serilog in a WCF application.   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;
                 


 
regards
Pat
pclarke7Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
pclarke7Connect With a Mentor Author Commented:
got this sorted myself. Set up logger as a global variable

    public static class MyGlobals
    {
           public static ILogger logger {get;set;}
    }

then

            catch(Exception ex)
            {
                MyGlobals.logger.Error("User: {UserName} Company: {Company} Transaction: {Transaction} Cur Seq:{Curseq} Next Seq:{Nextseq} Error:{Error} ", MyExe.userId, MyExe.companyId, MyExe.thisTransId, MyExe.curSeq, MyExe.nextSeq, ex);
            }
0
 
käµfm³d 👽Commented:
How are you hosting the WCF service? Will it be in IIS, or will it be a console application (or other)?
0
 
pclarke7Author Commented:
It will be in IIS
0
 
pclarke7Author Commented:
Didn't get an feedback except for one question about how I was hosting. Sorted out myself
0
All Courses

From novice to tech pro — start learning today.