Exemplo n.º 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();
    }
Exemplo n.º 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");
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
        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();
        }
Exemplo n.º 6
0
 public void Constructor_throws_if_passed_null_stream_creation_delegate()
 {
     // ReSharper disable once UnusedVariable
       var lazyStreamByteWriter = new LazyStreamByteWriter(null);
 }