End Google Ads 201810 - BS.net 01 --> I am seeing some odd behavior in the timer_Elapsed method of a service that I am working on.
(It is an event handler for a System.Timers.Timer instance.)

If I remove the section of code marked "Detect and restore failed FSW objects", the call to "_log.Append" works fine (the _log is an instance of the Logging class described below). However, when that section is included, the "_log.Append" fails to operate. Is it possible that it can prevent the preceeding method call?
Also, everything works fine on Server 2003; this only misbehaves on Server 2008.

/// /// The FileSystem watchers that monitor the specified folders.
/// private List _watchers = new List();


/// /// Automatic thread correction activity.
/// /// Sender object. /// Event args. private void timer_Elapsed(object sender, ElapsedEventArgs e)
{
_log.Append("Timer Cycle started.");

//Detect and restore failed FSW objects
try {
if ((from w in _watchers where w.Path == _firewallDirectory.Source select w.Path).Count() == 0)
{
FileSystemWatcher fw = new FileSystemWatcher(_firewallDirectory.Source);
fw.Created += new FileSystemEventHandler(fsw_Created);
fw.Renamed += new RenamedEventHandler(fsw_Renamed);
fw.EnableRaisingEvents = true;
_watchers.Add(fw);
}
}
catch (Exception ex)
{
_log.Append("ERROR in Timer - FSW Restore: " + ex.Message);
}
}



*** FYI: Simple Flat-File Logging Class ***

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace Logging
{
/// /// Encapsulates logging features for the application.
/// public class Log
{
#region Constructor

/// /// Default constructor.
/// /// The full file path for the log. public Log(string Path)
{
_logStream = new StreamWriter(Path, true);
}

#endregion Constructor

#region Private Properties

/// /// The text stream for the file.
/// private StreamWriter _logStream;

#endregion Private Properties

#region Public Methods

/// /// Adds a new line to the end of the log file.
/// /// The text to add to the Log. public void Append(string LineToAdd)
{
lock (_logStream)
{
_logStream.WriteLine(DateTime.Now.ToString() + " " + LineToAdd);
_logStream.Flush();
}
}

#endregion Public Methods
}
}