本文整理汇总了C#中TraceSource.Close方法的典型用法代码示例。如果您正苦于以下问题:C# TraceSource.Close方法的具体用法?C# TraceSource.Close怎么用?C# TraceSource.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TraceSource
的用法示例。
在下文中一共展示了TraceSource.Close方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestTcpTraceListener
public async Task TestTcpTraceListener()
{
var listener = new TcpListener(IPAddress.Loopback, 0);
listener.Start();
int port = ((IPEndPoint)listener.Server.LocalEndPoint).Port;
var traceSource = new TraceSource("UnitTestLogger");
traceSource.Listeners.Remove("Default");
traceSource.Switch.Level = SourceLevels.All;
traceSource.Listeners.Add(new TcpTraceListener(
IPAddress.Loopback, port,
new ExponentialBackoffTcpReconnectionPolicy()));
var listenerClient = await listener.AcceptTcpClientAsync();
traceSource.TraceEvent(TraceEventType.Information, 100, "Boris");
var receiverReader = new StreamReader(listenerClient.GetStream());
var line = await receiverReader.ReadLineAsync();
Assert.True(line.EndsWith("UnitTestLogger Information: 100 : Boris"));
listenerClient.Close();
listener.Stop();
traceSource.Close();
}
示例2: CloseTest
public void CloseTest()
{
var trace = new TraceSource("T1", SourceLevels.All);
trace.Listeners.Clear();
var listener = new TestTraceListener();
trace.Listeners.Add(listener);
trace.Close();
// NOTE: this assertion fails on .net 4.5
// where TraceSource.Close calls TraceListener.Close, not Dispose.
Assert.Equal(1, listener.GetCallCount(Method.Dispose));
// Assert that writing to a closed TraceSource is not an error.
trace.TraceEvent(TraceEventType.Critical, 0);
}
示例3: SendEventsBatchedByTime
public static void SendEventsBatchedByTime()
{
string tokenName = "batchedbytimetoken";
string indexName = "batchedbytimeindex";
SplunkCliWrapper splunk = new SplunkCliWrapper();
double testStartTime = SplunkCliWrapper.GetEpochTime();
string token = CreateIndexAndToken(splunk, tokenName, indexName);
var trace = new TraceSource("HttpEventCollectorLogger");
trace.Switch.Level = SourceLevels.All;
var meta = new HttpEventCollectorEventInfo.Metadata(index: indexName, source: "host", sourceType: "log", host: "customhostname");
var listener = new HttpEventCollectorTraceListener(
uri: new Uri("https://127.0.0.1:8088"),
token: token,
metadata: meta,
batchInterval: 1000);
trace.Listeners.Add(listener);
GenerateDataWaitForIndexingCompletion(splunk, indexName, testStartTime, trace);
trace.Close();
}
示例4: TestUdpTraceListener
public async Task TestUdpTraceListener()
{
int port = 11000;
var udpclient = new UdpClient(port);
var traceSource = new TraceSource("UnitTestLogger");
traceSource.Listeners.Remove("Default");
traceSource.Switch.Level = SourceLevels.All;
traceSource.Listeners.Add(new UdpTraceListener(IPAddress.Loopback, port));
traceSource.TraceEvent(TraceEventType.Information, 100, "Boris");
var dgram = await udpclient.ReceiveAsync();
var receivedText = Encoding.UTF8.GetString(dgram.Buffer);
Assert.Equal("UnitTestLogger Information: 100 : ", receivedText);
dgram = await udpclient.ReceiveAsync();
receivedText = Encoding.UTF8.GetString(dgram.Buffer);
Assert.Equal("Boris\r\n", receivedText);
udpclient.Close();
traceSource.Close();
}
示例5: VerifyFlushEvents
public void VerifyFlushEvents()
{
string tokenName = "flusheventtoken";
string indexName = "flusheventdindex";
SplunkCliWrapper splunk = new SplunkCliWrapper();
double testStartTime = SplunkCliWrapper.GetEpochTime();
string token = CreateIndexAndToken(splunk, tokenName, indexName);
splunk.StopServer();
Thread.Sleep(5 * 1000);
var trace = new TraceSource("HttpEventCollectorLogger");
trace.Switch.Level = SourceLevels.All;
var meta = new HttpEventCollectorEventInfo.Metadata(index: indexName, source: "host", sourceType: "log", host: "customhostname");
var listener = new HttpEventCollectorTraceListener(
uri: new Uri("https://127.0.0.1:8088"),
token: token,
retriesOnError: int.MaxValue,
metadata: meta);
trace.Listeners.Add(listener);
// Generate data, wait a little bit so retries are happenning and start Splunk. Expecting to see all data make it
const int eventsToGeneratePerLoop = 250;
const int expectedCount = eventsToGeneratePerLoop * 7;
int eventCounter = GenerateData(trace, eventsPerLoop: eventsToGeneratePerLoop);
splunk.StartServer();
trace.Close();
// Verify every event made to Splunk
splunk.WaitForIndexingToComplete(indexName, stabilityPeriod: 30);
int eventsFound = splunk.GetSearchCount("index=" + indexName);
Assert.Equal(expectedCount, eventsFound);
}
示例6: VerifyEventsAreInOrder
static void VerifyEventsAreInOrder()
{
string tokenName = "verifyeventsareinordertoken";
string indexName = "verifyeventsareinorderindex";
SplunkCliWrapper splunk = new SplunkCliWrapper();
double testStartTime = SplunkCliWrapper.GetEpochTime();
string token = CreateIndexAndToken(splunk, tokenName, indexName);
var trace = new TraceSource("HttpEventCollectorLogger");
trace.Switch.Level = SourceLevels.All;
var meta = new HttpEventCollectorEventInfo.Metadata(index: indexName, source: "host", sourceType: "log", host: "customhostname");
var listener = new HttpEventCollectorTraceListener(
uri: new Uri("https://127.0.0.1:8088"),
token: token,
metadata: meta);
trace.Listeners.Add(listener);
// Generate data
int totalEvents = 1000;
string[] filer = new string[2];
filer[0] = new string('s', 1);
filer[1] = new string('l', 100000);
for (int i = 0; i < totalEvents; i++)
{
trace.TraceInformation(string.Format("TraceInformation. This is event {0}. {1}", i, filer[i%2]));
}
string searchQuery = "index=" + indexName;
Console.WriteLine("{0} events were created, waiting for indexing to complete.", totalEvents);
splunk.WaitForIndexingToComplete(indexName);
int eventsFound = splunk.GetSearchCount(searchQuery);
Console.WriteLine("Indexing completed, {0} events were found. Elapsed time {1:F2} seconds", eventsFound, SplunkCliWrapper.GetEpochTime() - testStartTime);
// Verify all events were indexed correctly and in order
Assert.Equal(totalEvents, eventsFound);
List<string> searchResults = splunk.GetSearchResults(searchQuery);
Assert.Equal(searchResults.Count, eventsFound);
for (int i = 0; i< totalEvents; i++)
{
int id = totalEvents - i - 1;
string expected = string.Format("TraceInformation. This is event {0}. {1}", id, filer[id % 2]);
Assert.True(searchResults[i].Contains(expected));
}
trace.Close();
}
示例7: VerifyErrorsAreRaised
static void VerifyErrorsAreRaised()
{
string indexName = "errorindex";
string tokenName = "errortoken";
double testStartTime = SplunkCliWrapper.GetEpochTime();
SplunkCliWrapper splunk = new SplunkCliWrapper();
string token = CreateIndexAndToken(splunk, tokenName, indexName);
var trace = new TraceSource("HttpEventCollectorLogger");
trace.Switch.Level = SourceLevels.All;
var validMetaData = new HttpEventCollectorEventInfo.Metadata(index: indexName, source: "host", sourceType: "log", host: "customhostname");
var invalidMetaData = new HttpEventCollectorEventInfo.Metadata(index: "notexistingindex", source: "host", sourceType: "log", host: "customhostname");
var listenerWithWrongToken = new HttpEventCollectorTraceListener(
uri: new Uri("https://127.0.0.1:8088"),
token: "notexistingtoken",
metadata: validMetaData);
var listenerWithWrongUri = new HttpEventCollectorTraceListener(
uri: new Uri("https://127.0.0.1:8087"),
token: token,
metadata: validMetaData);
var listenerWithWrongMetadata = new HttpEventCollectorTraceListener(
uri: new Uri("https://127.0.0.1:8088"),
token: token,
metadata: invalidMetaData);
bool wrongTokenWasRaised = false;
listenerWithWrongToken.AddLoggingFailureHandler((HttpEventCollectorException e) =>
{
wrongTokenWasRaised = true;
});
bool wrongUriWasRaised = false;
listenerWithWrongUri.AddLoggingFailureHandler((HttpEventCollectorException e) =>
{
wrongUriWasRaised = true;
});
bool wrongMetaDataWasRaised = false;
listenerWithWrongMetadata.AddLoggingFailureHandler((HttpEventCollectorException e) =>
{
wrongMetaDataWasRaised = true;
});
trace.Listeners.Add(listenerWithWrongToken);
trace.Listeners.Add(listenerWithWrongUri);
trace.Listeners.Add(listenerWithWrongMetadata);
// Generate data
int eventCounter = GenerateData(trace);
Console.WriteLine("{0} events were created, waiting for errors to be raised.", eventCounter);
Thread.Sleep(30 * 1000);
trace.Close();
Assert.True(wrongTokenWasRaised);
Assert.True(wrongUriWasRaised);
Assert.True(wrongMetaDataWasRaised);
}