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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T00:28:38+00:00 2026-05-18T00:28:38+00:00

I recently created a Windows service. One thing that it faithfully does is log

  • 0

I recently created a Windows service. One thing that it faithfully does is log any errors to the Application log. I have the following code that does this:

Dim appLog = New System.Diagnostics.EventLog With {.Source = "MyService"}
appLog.WriteEntry(message, EventLogEntryType.Error, transactionID)

I also have the following in my app.config:

<system.diagnostics>
    <sources>
      <source name="MyService" switchName="DefaultSwitch">
        <listeners>
          <!--<add name="FileLog"/>-->          
          <add name="EventLog"/>
        </listeners>
      </source>
    </sources>
    <switches>
      <add name="DefaultSwitch" value="Information" />
    </switches>
    <sharedListeners>
      <!--<add name="FileLog"
           type="Microsoft.VisualBasic.Logging.FileLogTraceListener, Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"
           initializeData="FileLogWriter"/>-->      
      <add name="EventLog" type="System.Diagnostics.EventLogTraceListener" initializeData="MyService"/> 
    </sharedListeners>
  </system.diagnostics>

I would expect that my code above should work even without setting the Source property of EventLog programmatically because I’ve already defined the source in the config file. But if I remove With {.Source = "MyService"}, then I get an Exception, which that says that the Source property should be set before calling WriteEntry method. So, what’s purpose of the stuff in the configuration XML?

  • 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-18T00:28:38+00:00Added an answer on May 18, 2026 at 12:28 am

    As luck has it, I’ve stumbled on an answer, or at least a partial one while working on a different app. The settings in the config file matter when using My.Application.Log object. For example: My.Application.Log.WriteEntry(errMsg) will write to a file or to the Event Viewer depending on the setting in app.config.

    So, in this case, the EventLog class is not called directly from code. This gives me the extra flexibility to “hot-swap” the log format from Event Viewer to file, for example, without changing any code or recompiling. One thing that I did notice though is that the Name property of the <source> element needs to be set to “DefaultSource”. Otherwise, events don’t get logged. There’s probably a way to change that, but I didn’t see a need, so I didn’t investigate further. Hopefully, this will be useful to somebody.

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

Sidebar

Related Questions

I recently created a WCF service that works fine when tested from Visual Studio
We have a Windows Service created in .Net 4.0, the services parses large text
I've created an application in C# which I run as a Windows Service. This
I recently created a windows service which can wear various hats depending on what
I want to create an easy application for windows mobile devices, i have recently
I recently created an auto browser windows form app that browsers various places just
Recently I have purchased a notebook that came with Windows Home Basic (that don't
Recently I've created a weather application for windows phone 7 using C#. But it
I recently created a advanced form with elements that use jquery's $().hide & $().show
I recently created a generic Matrix<T> class that acts as a wrapper around a

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.