本文整理汇总了C#中TraceSource类的典型用法代码示例。如果您正苦于以下问题:C# TraceSource类的具体用法?C# TraceSource怎么用?C# TraceSource使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TraceSource类属于命名空间,在下文中一共展示了TraceSource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: NewLogicalOperationPushedOnToStack
public void NewLogicalOperationPushedOnToStack()
{
var traceSource = new TraceSource(MethodBase.GetCurrentMethod().Name, SourceLevels.All);
using (new LogicalOperationScope(traceSource, traceSource.Name))
Assert.Equal("NewLogicalOperationPushedOnToStack", Trace.CorrelationManager.LogicalOperationStack.Peek());
}
示例2: SetSourceSwitchTest
public void SetSourceSwitchTest()
{
var trace = new TraceSource("TestTraceSource");
var @switch = new SourceSwitch("TestTraceSwitch");
trace.Switch = @switch;
Assert.Equal(@switch, trace.Switch);
}
示例3: Associate
internal static void Associate(TraceSource traceSource, object objA, object objB)
{
if (ValidateSettings(traceSource, TraceEventType.Information))
{
PrintLine(traceSource, TraceEventType.Information, 0, "Associating " + (GetObjectName(objA) + "#" + ValidationHelper.HashString(objA)) + " with " + (GetObjectName(objB) + "#" + ValidationHelper.HashString(objB)));
}
}
示例4: Enter
internal static void Enter(TraceSource source, string method)
{
if(source.Switch.ShouldTrace(TraceEventType.Verbose))
{
source.TraceEvent(TraceEventType.Verbose, 0, "Entering --> " + method);
}
}
示例5: Leave
internal static void Leave(TraceSource source, string message)
{
if (source.Switch.ShouldTrace(TraceEventType.Verbose))
{
source.TraceEvent(TraceEventType.Verbose, 0, "Leaving <-- " + message);
}
}
示例6: 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();
}
示例7: Run
public override void Run()
{
try
{
var m = Helper.FormatTrace("Staring the Scheduler", "SchedulerWorkerRole", "Run");
var traceSource = new TraceSource("VirtoCommerce.ScheduleService.Trace");
traceSource.TraceEvent(TraceEventType.Information, 0, m);
string cloudContext;
if (RoleEnvironment.IsAvailable)
{
cloudContext = String.Format("{0}|{1}",
RoleEnvironment.DeploymentId,
RoleEnvironment.CurrentRoleInstance.Id);
}
else
{
cloudContext = Guid.NewGuid().ToString();
}
var jobScheduler = new JobScheduler(cloudContext, traceSource, () => AzureConfiguration.Instance.AzureStorageAccount, new Settings());
traceSource.TraceEvent(TraceEventType.Information, 0, Helper.FormatTrace("Staring the Scheduler", "SchedulerWorkerRole", "Run", "Starting Paralel.Invoke", cloudContext));
Parallel.Invoke(
jobScheduler.JobsManagerProcess,
jobScheduler.SchedulerProcess);
}
catch (Exception ex)
{
var m = Helper.FormatException(ex, "WorkerRole", "Run");
var traceSource = new TraceSource("VirtoCommerce.ScheduleService.Trace");
traceSource.TraceEvent(TraceEventType.Error, 0, m);
}
}
示例8: EmailFloodManyThreadsMax100
public void EmailFloodManyThreadsMax100()
{
TraceSource source = new TraceSource("emailFlood2Source");
Action d = () =>
{
try
{
var guid = Guid.NewGuid();
source.TraceEvent(TraceEventType.Warning, 0, "Message 1 - {0}", guid);
source.TraceEvent(TraceEventType.Error, 0, "Message 2 - {0}", guid);
}
catch (Exception ex)
{
Debug.WriteLine(string.Format("Action exception: {0}", ex));
}
};
for (int i = 0; i < 200; i++)
{
d.BeginInvoke(null, null);
}
// Need to wait, otherwise messages haven't been sent and Assert throws exception
System.Threading.Thread.Sleep(3000);
AssertMessagesSent(100, "Should be limited by max traces of 100.");
}
示例9: CanDisposeRepeatedly
public void CanDisposeRepeatedly()
{
var traceSource = new TraceSource(MethodBase.GetCurrentMethod().Name, SourceLevels.All);
using (var context = new LogicalOperationScope(traceSource, traceSource.Name))
context.Dispose();
}
示例10: Main
static void Main(string[] args)
{
EnableSelfSignedCertificates();
Uri uri = new Uri("https://localhost:8088");
string token = "BEC47D17-AC4A-49ED-834B-969745D24550";
var trace = new TraceSource("conf-demo");
trace.Switch.Level = SourceLevels.All;
var listener = new HttpEventCollectorTraceListener(uri, token);
trace.Listeners.Add(listener);
HashSet<string> files = new HashSet<string>();
while (true)
{
string[] currentFiles = Directory.GetFiles(args[0]);
foreach (string s in currentFiles)
{
if (!files.Contains(s))
{
files.Add(s);
string ascii = ToAscii(s.Substring(s.LastIndexOf('\\') + 1), new Bitmap(s, true));
trace.TraceInformation(ascii);
trace.Flush();
}
}
Thread.Sleep(200);
}
}
示例11: ReturnName
public void ReturnName()
{
var traceSource = new TraceSource(MethodBase.GetCurrentMethod().Name, SourceLevels.All);
using (var context = new LogicalOperationScope(traceSource, traceSource.Name))
Assert.Equal(traceSource.Name, context.ToString());
}
示例12: Invoke
public Task Invoke(IDictionary<string, object> env)
{
// The TraceSource is assumed to be the same across all requests.
traceSource = traceSource ?? new Request(env).Get<TraceSource>("host.TraceSource");
if (traceSource == null)
{
return nextApp(env);
}
try
{
TraceCall(env);
return nextApp(env).Then(() =>
{
TraceResult(env);
})
.Catch(errorInfo =>
{
TraceException(errorInfo.Exception, "asynchronously");
return errorInfo.Throw();
});
}
catch (Exception ex)
{
TraceException(ex, "synchronously");
throw;
}
}
示例13: ShouldLogNetworkCommunication
public void ShouldLogNetworkCommunication()
{
// Setup source and listener
string initializationString =
@"name = XmlLogger; logrootpath = c:\logs\; staticpattern = lognc_; maxSizeBytes = 200000;";
XmlWriterRollingTraceListener traceListener =
new XmlWriterRollingTraceListener(initializationString);
TraceSource log = new TraceSource("Test", SourceLevels.All);
log.Listeners.Clear();
log.Listeners.Add(traceListener);
// Start Activity #1
Guid activity1Guid = Guid.NewGuid();
Trace.CorrelationManager.ActivityId = activity1Guid;
log.TraceEvent(TraceEventType.Start, 2, "Activity #1");
// log information inside Activity #1
log.TraceInformation("Going to execute HttpWebRequest from Activity #1");
HttpWebRequest request = HttpWebRequest.Create("http://www.google.com/") as HttpWebRequest;
WebResponse response = request.GetResponse();
using (StreamReader s = new StreamReader(response.GetResponseStream()))
{
string value = s.ReadToEnd();
}
// Complete Activity #1
log.TraceEvent(TraceEventType.Stop, 8, "Completing Activity #1");
}
示例14: TraceListenerEx
public TraceListenerEx(TraceSource source)
{
if (source == null)
throw new ArgumentNullException("source");
_source = source;
}
示例15: TraceInternal
private static void TraceInternal(TraceSource traceSource, int eventId, TraceLevel traceLevel, string message)
{
if (traceSource == null)
return;
var traceEventType = ConvertTraceLevelToTraceEventType(traceLevel);
traceSource.TraceEvent(traceEventType, eventId, message);
}