?
Solved

How to initialize the Serilog logger in a WCF service

Posted on 2015-01-23
4
Medium Priority
?
678 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

Linux Academy Android App Now Supports Chromecast

We have some fantastic news for our Android fans. We’re so excited to announce that the Linux Academy Android app is now available with Chromecast support. That’s right – simply download the latest update of the Linux Academy App and start casting your favorite course videos!

Question has a verified solution.

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

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

777 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