Solved

How to initialize the Serilog logger in a WCF service

Posted on 2015-01-23
4
612 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

728 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