Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 471167
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T23:57:31+00:00 2026-05-12T23:57:31+00:00

I am hosting WCF service in console application(just temporary, I will move to service

  • 0

I am hosting WCF service in console application(just temporary, I will move to service later. Using administrator account). After several hours of execution I get Critical Error from Console(HOST) and my service stop working. What is the best method to trace error?
I have tried code below to log error but it seems code do not catch error. I think I need to handle error inside in WCF service not in host application.
Any suggestions?

namespace ConsoleApplication1
{
    //test host project
    class Program
    {
        static void Main(string[] args)
        {                     

            using (var serviceHost = new ServiceHost(new ServicePdf()))
            {
                try
                {                    
                    serviceHost.Open();
                    Console.WriteLine("Service was succesfully hosted. Press [enter] to exit...");
                    Console.ReadLine();                    
                }
                catch (Exception ex)
                {                    
                    MethodToLogError(ex);
                    Console.WriteLine("Error occured while hosting service. Press [enter] to exit...");
                    Console.WriteLine(ex.Message);
                    Console.ReadLine();
                }
            }
        }
    }
}

Regards,
Tomas

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T23:57:31+00:00Added an answer on May 12, 2026 at 11:57 pm

    You can catch any unhandled exception in your host (whether from the main thread or any other thread) by suscribing to the AppDomain.UnhandledException event.

    static void Main(string[] args)
            {  
                //...
                AppDomain.CurrentDomain.UnhandledException += exceptionHandler;
                //...
    }
    
    static void exceptionHandler(object sender, UnhandledExceptionEventArgs args) 
    {
          Exception e = (Exception) args.ExceptionObject;
          Console.WriteLine("An unhandledexception occurred. Time to die. " + e);
    }
    

    This way you get to log the exception. No way to gracefully recover from it this way, though.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Console application hosting a WCF service. I would like to be
I am using a wcf service that I created, when both hosting machine and
I am making a basic self hosting WCF service, and I was just wondering
I am hosting a WCF service using HTTPS, and I am running into a
When hosting a WCF service on IIS you have an option of manually configuring
I am hosting a WCF service in a Windows Service on one of our
From what I've seen the tag is ignored when hosting a WCF service in
This is in relation to this question I am hosting this WCF service in
I'm hosting my first WCF service in IIS. I have two methods, 1 to
I created a wcf service based on ServiceHostFactory, and i'm hosting it in IIS6.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.