using System;
using System.Configuration;
using System.IO;
using ZocMonLib;

namespace ZocMonLib
{
    public class RecordReduceStatusSourceProviderFile : RecordReduceStatusSourceProvider
    {
        private readonly ISystemLogger _logger;
        private readonly string _reducingStatusTxt = ConfigurationManager.AppSettings["ZocMonIsReducingFilePath"];

        public RecordReduceStatusSourceProviderFile(ISettings settings)
        {
            _logger = settings.LoggerProvider.CreateLogger(typeof(RecordReduceStatusSourceProviderFile));
        }

        public override string ReadValue()
        {
            var status = SeedValue();
            try
            {
                if (File.Exists(_reducingStatusTxt))
                {
                    using (TextReader reader = new StreamReader(_reducingStatusTxt))
                        status = reader.ReadLine();
                }
            }
            catch (Exception e)
            {
                _logger.Fatal("Something went wrong Reading from " + _reducingStatusTxt, e);
            }
            return status;
        }

        public override void WriteValue(string value)
        {
            try
            {
                if (!File.Exists(_reducingStatusTxt))
                    File.Create(_reducingStatusTxt).Dispose();

                using (TextWriter writer = new StreamWriter(_reducingStatusTxt))
                    writer.WriteLine(value);
            }
            catch (Exception e)
            { 
                _logger.Fatal("Something went wrong Reading from " + _reducingStatusTxt, e);
            }
        }
    }
}
using System;
using System.Configuration;
using System.IO;
using ZocMonLib;

namespace ZocMonLib
{
    public class RecordReduceStatusSourceProviderFile : RecordReduceStatusSourceProvider
    {
        private readonly ISystemLogger _logger;
        private readonly string _reducingStatusTxt = ConfigurationManager.AppSettings["ZocMonIsReducingFilePath"];

        public RecordReduceStatusSourceProviderFile(ISettings settings)
        {
            _logger = settings.LoggerProvider.CreateLogger(typeof(RecordReduceStatusSourceProviderFile));
        }

        public override string ReadValue()
        {
            var status = SeedValue();
            try
            {
                if (File.Exists(_reducingStatusTxt))
                {
                    using (TextReader reader = new StreamReader(_reducingStatusTxt))
                    {
                        var temp = reader.ReadLine();
                        if (IsValid(temp))
                            status = temp;
                        else
                            _logger.Fatal(String.Format("Value in {0} is invalid: {1} - sould be 1 or 0", _reducingStatusTxt, temp));
                    }
                }
            }
            catch (Exception e)
            {
                _logger.Fatal("Something went wrong Reading from " + _reducingStatusTxt, e);
            }
            return status;
        }

        public override void WriteValue(string value)
        {
            try
            {
                if (!File.Exists(_reducingStatusTxt))
                    File.Create(_reducingStatusTxt).Dispose();

                using (TextWriter writer = new StreamWriter(_reducingStatusTxt))
                    writer.WriteLine(value);
            }
            catch (Exception e)
            { 
                _logger.Fatal("Something went wrong Reading from " + _reducingStatusTxt, e);
            }
        }
    }
}
Add extra checks around the trusting of the value in the file. By default we wont pull over anything invalid and log out when something is wroung.
Add extra checks around the trusting of the value in the file. By default we wont pull over anything invalid and log out when something is wroung.
