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 8618697
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:10:23+00:00 2026-06-12T06:10:23+00:00

When creating an instance of a service using TopShelf I’d like to be able

  • 0

When creating an instance of a service using TopShelf I’d like to be able to access the service instance name(which may have been set on the command line during installation as a service; which means I don’t have direct access to it) to be able to use that as a property for the log file name in Log4Net.

In the example code below we set various properties which are available to use for logging in the global context. I’d love to be able to set the Service instance name here also; but can’t seem to be able to get access to it during host initialization.

Anyone any suggestions as to how I could access the service instance name value at run time with Topshelf.

The example below is part of a common function which all our services use to start a service using Topshelf.

public static TopshelfExitCode Run(Func<IConsumerController> controllerFactory,
    string serviceName,
    string serviceDescription)
{
    // Initialise the Global log4net properties so we can use them for log file names and logging when required.
    log4net.GlobalContext.Properties["custom-assembly"] = System.IO.Path.GetFileNameWithoutExtension(System.Reflection.Assembly.GetEntryAssembly().Location);
    log4net.GlobalContext.Properties["custom-processname"] = System.Diagnostics.Process.GetCurrentProcess().ProcessName;
    log4net.GlobalContext.Properties["custom-process-id"] = System.Diagnostics.Process.GetCurrentProcess().Id;
// WOULD LIKE ACCESS TO THE SERVICE INSTANCE NAME HERE
    var logFileInfo = new System.IO.FileInfo(".\\Log.config");
    log4net.Config.XmlConfigurator.Configure(logFileInfo);

    var host = HostFactory.New(r =>
    {
        var controller = controllerFactory();
        r.Service<ConsumerService>( () => new ConsumerService(controller));
        r.SetServiceName(serviceName);
        r.SetDescription(serviceDescription + " © XYZ Ltd. 2012");
        r.SetDisplayName(serviceDescription + " © XYZ Ltd. 2012");
        r.StartAutomatically();
        r.EnablePauseAndContinue();
        r.RunAsLocalSystem();
    });
    return host.Run();
}
  • 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-06-12T06:10:24+00:00Added an answer on June 12, 2026 at 6:10 am

    The instance name is passed on the command line, you can access the command line arguments and pull it from there. This might take a little tweaking, but if you look at the ServiceInstaller you can see how we adjust the command path via registry editing once the service is installed.

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

Sidebar

Related Questions

I have problem creating new instance of excel 2007 using VBA (from Access 2002).
I am creating a web service, I have added an operation which receive an
I am creating a silverlight card game which talks to a WCF service using
I am having a problem creating a WCF service instance with a parameter. The
I'm having trouble creating an instance of a class using Python's re module. Here's
I'm using the Ninject Factory Extension and creating a custom instance provider explained in
I am using JBoss 4.0 for creating a simple Web Service using the @WebService
I have been technically testing a WCF service recently and have got to the
I have successfully started using Azure AppFabric Caching Service, but I' not sure what
I am creating a web service with spring + jetty + cxf using the

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.