Solved

How to initialize the Serilog logger in a WCF service

Posted on 2015-01-23
4
481 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
  • 3
4 Comments
 
LVL 74

Expert Comment

by:käµfm³d 👽
Comment Utility
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
Comment Utility
It will be in IIS
0
 

Accepted Solution

by:
pclarke7 earned 0 total points
Comment Utility
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
Comment Utility
Didn't get an feedback except for one question about how I was hosting. Sorted out myself
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
How Can I fix my MouseHover Event? 14 26
ASP.net pdf file opening in debug mode but not on web 13 23
Wpf develop 5 29
Showdialog 8 20
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…
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

763 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now