Solved

How to initialize the Serilog logger in a WCF service

Posted on 2015-01-23
4
589 Views
Last Modified: 2015-02-02
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
0
Comment
Question by:pclarke7
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 40567623
How are you hosting the WCF service? Will it be in IIS, or will it be a console application (or other)?
0
 

Author Comment

by:pclarke7
ID: 40568019
It will be in IIS
0
 

Accepted Solution

by:
pclarke7 earned 0 total points
ID: 40576121
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
 

Author Closing Comment

by:pclarke7
ID: 40583558
Didn't get an feedback except for one question about how I was hosting. Sorted out myself
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question