public void MultiplePartitionKeysTest() { var logFactory = new LogFactory(); var logConfig = new Config.LoggingConfiguration(logFactory); logConfig.Variables["ConnectionString"] = nameof(BlobStorageTargetTest); var cloudBlobService = new CloudBlobServiceMock(); var blobStorageTarget = new BlobStorageTarget(cloudBlobService); blobStorageTarget.ConnectionString = "${var:ConnectionString}"; blobStorageTarget.Container = "${level}"; blobStorageTarget.BlobName = "${logger}"; blobStorageTarget.Layout = "${message}"; logConfig.AddRuleForAllLevels(blobStorageTarget); logFactory.Configuration = logConfig; for (int i = 0; i < 50; ++i) { logFactory.GetLogger("Test1").Info("Hello"); logFactory.GetLogger("Test2").Debug("Goodbye"); } logFactory.Flush(); Assert.Equal(2, cloudBlobService.AppendBlob.Count); // Two partitions Assert.NotEqual(string.Empty, cloudBlobService.PeekLastAppendBlob("info", "Test1")); Assert.NotEqual(string.Empty, cloudBlobService.PeekLastAppendBlob("debug", "Test2")); }
public void SingleLogEventTest() { var logFactory = new LogFactory(); var logConfig = new Config.LoggingConfiguration(logFactory); logConfig.Variables["ConnectionString"] = nameof(BlobStorageTargetTest); var cloudBlobService = new CloudBlobServiceMock(); var blobStorageTarget = new BlobStorageTarget(cloudBlobService); blobStorageTarget.ConnectionString = "${var:ConnectionString}"; blobStorageTarget.Container = "${level}"; blobStorageTarget.BlobName = "${logger}"; blobStorageTarget.Layout = "${message}"; blobStorageTarget.BlobTags.Add(new TargetPropertyWithContext() { Name = "MyTag", Layout = "MyTagValue" }); blobStorageTarget.BlobMetadata.Add(new TargetPropertyWithContext() { Name = "MyMetadata", Layout = "MyMetadataValue" }); logConfig.AddRuleForAllLevels(blobStorageTarget); logFactory.Configuration = logConfig; logFactory.GetLogger("Test").Info("Hello World"); logFactory.Flush(); Assert.Equal(nameof(BlobStorageTargetTest), cloudBlobService.ConnectionString); Assert.Single(cloudBlobService.BlobMetadata); Assert.Contains(new KeyValuePair <string, string>("MyMetadata", "MyMetadataValue"), cloudBlobService.BlobMetadata); Assert.Single(cloudBlobService.BlobTags); Assert.Contains(new KeyValuePair <string, string>("MyTag", "MyTagValue"), cloudBlobService.BlobTags); Assert.Single(cloudBlobService.AppendBlob); // One partition Assert.Equal("Hello World" + System.Environment.NewLine, cloudBlobService.PeekLastAppendBlob("info", "Test")); }