Example #1
0
    private static void Main()
    {
      Logger.LogLevel = LoggingSettings.Settings.Level;

      var rootDir = LoggingSettings.Settings.DirPath;
      if (string.IsNullOrWhiteSpace(rootDir))
        rootDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);

      var logEncoder = new XmlLogEncoder();

      var byteWriter = new LazyStreamByteWriter(() => FileStreamFactory.CreateFileStream(
        Path.Combine(rootDir, Resources.SubdirectoryName)));

      Logger.AddLogWriter(new Lazy<ILogWriter>(() => new LogWriter(logEncoder, byteWriter)));

      // LogMsg message 1
      Logger.Log(LogLevel.Error, "id-str1");

      const string param = "param-str";

      // LogMsg message 2
      Logger.Log(LogLevel.Error, "id-str2", param, null);

      Fn();
    }
Example #2
0
        private static void Main(string[] args)
        {
            var logEncoder = new XmlLogEncoder();
              var byteWriter = new LazyStreamByteWriter(FileStreamFactory.CreateApplicationDataFileStream);
              var logWriter = new LogWriter(logEncoder, new[] {byteWriter});
              Logger.AddLogWriter(logWriter);

              Logger.Log(LogLevel.Error, "message");
        }
        public void WriteBytes_does_not_create_stream_if_passed_null_bytes()
        {
            var createCalls = 0;

              var lazyStreamByteWriter = new LazyStreamByteWriter(delegate
              {
            ++createCalls;
            return null;
              });

              Assert.AreEqual(0, createCalls);

              lazyStreamByteWriter.WriteBytes(null);

              Assert.AreEqual(0, createCalls);
        }
        public void WriteBytes_causes_stream_to_be_created_but_only_on_first_call()
        {
            var createCalls = 0;

              var lazyStreamByteWriter = new LazyStreamByteWriter(delegate
              {
            ++createCalls;
            return null;
              });

              Assert.AreEqual(0, createCalls);

              lazyStreamByteWriter.WriteBytes(new byte[] {1});

              Assert.AreEqual(1, createCalls);

              lazyStreamByteWriter.WriteBytes(new byte[] {1});

              // Second call doesn't attempt to create stream
              Assert.AreEqual(1, createCalls);
        }
        public void WriteBytes_writes_then_flushes_stream()
        {
            var stream = Substitute.For<Stream>();
              var lazyStreamByteWriter = new LazyStreamByteWriter(() => stream);

              var bytes = new byte[] {1, 2, 3};
              lazyStreamByteWriter.WriteBytes(bytes);

              stream.Received(1).Write(bytes, 0, bytes.Length);
              stream.Received(1).Flush();
        }
 public void Constructor_throws_if_passed_null_stream_creation_delegate()
 {
     // ReSharper disable once UnusedVariable
       var lazyStreamByteWriter = new LazyStreamByteWriter(null);
 }