本文整理汇总了C#中System.Diagnostics.TraceSource.TraceEvent方法的典型用法代码示例。如果您正苦于以下问题:C# TraceSource.TraceEvent方法的具体用法?C# TraceSource.TraceEvent怎么用?C# TraceSource.TraceEvent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Diagnostics.TraceSource
的用法示例。
在下文中一共展示了TraceSource.TraceEvent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Run
private 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);
var 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);
}
}
示例2: Main
static void Main(string[] args)
{
TraceSource myTraceSource = new TraceSource("MyConsoleApp");
myTraceSource.TraceEvent(TraceEventType.Error, 1, "Tracing Error Message.");
myTraceSource.TraceEvent(TraceEventType.Warning, 2, "Tracing Warning Message.");
myTraceSource.TraceEvent(TraceEventType.Information, 3, "Tracing Information.");
myTraceSource.TraceEvent(TraceEventType.Verbose, 4, "Tracing Verbose Message.");
myTraceSource.TraceEvent(TraceEventType.Critical, 5, "Tracing Critical Message.");
myTraceSource.Close();
}
示例3: Main
private static void Main(string[] args)
{
using (CancellationTokenSource cts = new CancellationTokenSource())
{
TraceSource traceSource = new TraceSource("CleanupSample", SourceLevels.All);
traceSource.Listeners.Add(new ConsoleTraceListener() { TraceOutputOptions = TraceOptions.DateTime | TraceOptions.ThreadId });
CleanupGuard guard = new CleanupGuard();
Task task = guard.RunAsync(g => RunSampleAsync(g, traceSource, cts.Token));
Console.WriteLine("Press ENTER to stop.");
Console.ReadLine();
cts.Cancel();
try
{
task.Wait();
}
catch (Exception e)
{
traceSource.TraceEvent(TraceEventType.Error, 0, "ERROR: {0}", e);
}
}
}
示例4: Index
public ActionResult Index()
{
// Get most popular albums
var albums = GetTopSellingAlbums(5);
var albumCount = GetTotalAlbumns();
Trace.Write(string.Format("Total number of Albums = {0} and Albums with 'The' = {1}", albumCount.Item1, albumCount.Item2));
Trace.Write("Got top 5 albums");
Trace.TraceWarning("Test TraceWarning;");
Trace.IndentLevel++;
Trace.TraceError("Test TraceError;");
Trace.Write("Another trace line");
Trace.IndentLevel++;
Trace.Write("Yet another trace line");
Trace.IndentLevel = 0;
Trace.TraceInformation("Test TraceInformation;");
HttpContext.Session["TestObject"] = new Artist { ArtistId = 123, Name = "Test Artist" };
TraceSource ts = new TraceSource("Test source");
ts.TraceEvent(TraceEventType.Warning, 0, string.Format("{0}: {1}", "trace", "source"));
return View(albums);
}
示例5: UsesTraceSource
public void UsesTraceSource()
{
Console.WriteLine("Config:"+ AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);
Assert.AreEqual("FromAppConfig", ConfigurationManager.AppSettings["appConfigCheck"]);
// just ensure, that <system.diagnostics> is configured for our test
Trace.Refresh();
TraceSource ts = new TraceSource("TraceLoggerTests", SourceLevels.All);
Assert.AreEqual(1, ts.Listeners.Count);
Assert.AreEqual(typeof(CapturingTraceListener), ts.Listeners[0].GetType());
CapturingTraceListener.Events.Clear();
ts.TraceEvent(TraceEventType.Information, 0, "message");
Assert.AreEqual(TraceEventType.Information, CapturingTraceListener.Events[0].EventType);
Assert.AreEqual("message", CapturingTraceListener.Events[0].FormattedMessage);
// reset events and set loggerFactoryAdapter
CapturingTraceListener.Events.Clear();
NameValueCollection props = new NameValueCollection();
props["useTraceSource"] = "TRUE";
TraceLoggerFactoryAdapter adapter = new TraceLoggerFactoryAdapter(props);
adapter.ShowDateTime = false;
LogManager.Adapter = adapter;
ILog log = LogManager.GetLogger("TraceLoggerTests");
log.WarnFormat("info {0}", "arg");
Assert.AreEqual(TraceEventType.Warning, CapturingTraceListener.Events[0].EventType);
Assert.AreEqual("[WARN] TraceLoggerTests - info arg", CapturingTraceListener.Events[0].FormattedMessage);
}
示例6: WriteLog
/// <summary>
/// 写日志
/// </summary>
/// <param name="type"></param>
/// <param name="id"></param>
/// <param name="msg"></param>
public static void WriteLog(TraceEventType type, int id, string msg)
{
string direct = HttpContext.Current.Server.MapPath("~/Log/Api/");
if (!Directory.Exists(direct))
Directory.CreateDirectory(direct);
string file = direct + DateTime.Now.ToString("yyyy-MM-dd") + ".txt";
TextWriterTraceListener listen = new TextWriterTraceListener(file);
listen.TraceOutputOptions = TraceOptions.ProcessId |
TraceOptions.ThreadId |
TraceOptions.Timestamp |
TraceOptions.DateTime |
TraceOptions.LogicalOperationStack;
//TraceOptions.Callstack;
Trace.Listeners.Add(listen);
Trace.AutoFlush = false;
//Trace.WriteLine("Test");
SourceSwitch sourceSwitch = new SourceSwitch("sourceSwitch");
sourceSwitch.Level = SourceLevels.Verbose;
TraceSource traceSource = new TraceSource("traceSource");
traceSource.Switch = sourceSwitch;
traceSource.Listeners.Add(listen);
traceSource.TraceEvent(type, id, msg);
Trace.Close();
}
示例7: ActivityNameForXmlListenersStrangeCharacters
public void ActivityNameForXmlListenersStrangeCharacters()
{
TraceSource source = new TraceSource("testScopeSource");
var listener = source.Listeners.OfType<TestTraceListener>().First();
listener.MethodCallInformation.Clear();
string transferIn = "TransferIn";
string start = "<";
string transferOut = "TransferOut";
string stop = "Stopping...";
var activityName = "<";
using (var scope = new ActivityScope(source, 11, 12, 13, 14, transferIn, start, transferOut, stop, activityName))
{
source.TraceEvent(TraceEventType.Warning, 2, "B");
}
var events = listener.MethodCallInformation;
StringAssert.StartsWith(events[0].Message, transferIn);
Console.WriteLine(string.Join(",", events[1].Data));
Assert.AreEqual(1, events[1].Data.Length);
Assert.IsInstanceOfType(events[1].Data[0], typeof(XPathNavigator));
var navigator = (XPathNavigator)events[1].Data[0];
var resolver = new XmlNamespaceManager(navigator.NameTable);
resolver.AddNamespace("ns1", "http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord");
resolver.AddNamespace("ns2", "http://schemas.microsoft.com/2006/08/ServiceModel/DictionaryTraceRecord");
Assert.AreEqual(start, navigator.SelectSingleNode("/ns1:TraceRecord/ns1:Description", resolver).Value);
Assert.AreEqual(activityName, navigator.SelectSingleNode("/ns1:TraceRecord/ns2:ExtendedData/ns2:ActivityName", resolver).Value);
//StringAssert.Contains(events[1].Data[0].ToString(), activityName);
//StringAssert.Contains(events[1].Data[0].ToString(), start);
StringAssert.StartsWith(events[3].Message, transferOut);
Assert.AreEqual(stop, events[4].Message);
}
示例8: TraceLogger
internal static Action<TraceEventType, Guid?, string, string> TraceLogger()
{
TraceSource _traceSource = new TraceSource("SikkerDigitalPost.Klient");
return (severity, koversasjonsId, caller, message) =>
{
_traceSource.TraceEvent(severity, 1, "[{0}, {1}] {2}", koversasjonsId.GetValueOrDefault(), caller, message);
};
}
示例9: JustForTestingLoggingConfiguration
public void JustForTestingLoggingConfiguration()
{
TraceSource traceSource = new TraceSource("DiagnosticsTracePerformanceTest");
traceSource.TraceEvent(TraceEventType.Verbose, -1, "test trace info {0}", new MyTestObjectUnderTrace());
// Trace.TraceInformation("traced info");
Trace.WriteLine("some message", "myCategory");
Console.WriteLine("from console");
}
示例10: ConfigTest
public void ConfigTest()
{
var source = new TraceSource("MSMQTEST", SourceLevels.All);
source.TraceInformation("test1");
source.TraceEvent(TraceEventType.Error, 1, "Test 2 {0}", 123);
}
示例11: TraceSource
public ActionResult TraceSource(string id)
{
HttpContext.Items.Add(IntegrationTestTab.Expected, id);
var traceSource = new TraceSource("Test Source");
traceSource.TraceEvent(TraceEventType.Warning, 0, id);
return View(model: id);
}
示例12: TraceEvent
public static void TraceEvent(TraceEventType type, string message)
{
TraceSource ts = new TraceSource(TraceSource);
if (Trace.CorrelationManager.ActivityId == Guid.Empty)
{
Trace.CorrelationManager.ActivityId = Guid.NewGuid();
}
ts.TraceEvent(type, 0, message);
}
示例13: Main
public static void Main(string[] args)
{
TraceSource traceSource = new TraceSource("myTraceSource", SourceLevels.All);
traceSource.TraceInformation("Tracing application...");
traceSource.TraceEvent(TraceEventType.Critical, 0, "Critical trace");
traceSource.TraceData(TraceEventType.Information, 1, new object[] { "a", "b", "c" });
traceSource.Flush();
traceSource.Close();
}
示例14: HowToUseTheTraceSourceClass
public static void HowToUseTheTraceSourceClass()
{
TraceSource traceSource = new TraceSource("myTraceSource", SourceLevels.All);
traceSource.TraceInformation("Tracing app");
traceSource.TraceEvent(TraceEventType.Critical, 0, "Critical trace");
traceSource.TraceData(TraceEventType.Information, 1, new object[] { "a", "b", "c" });
traceSource.Flush();
traceSource.Close();
}
示例15: SetTraceSource
/// <summary>
/// Sets the trace source for all instances of <see cref="EFTracingConnection"/>.
/// </summary>
/// <param name="connection">The connection.</param>
/// <param name="traceSource">The trace source to which to trace SQL command activity.</param>
public static void SetTraceSource(this DbConnection connection, TraceSource traceSource)
{
Contract.Requires(connection != null);
Contract.Requires(traceSource != null);
foreach (var tracingConnection in connection.GetTracingConnections())
{
tracingConnection.CommandExecuting += (_, e) => traceSource.TraceInformation(e.ToFlattenedTraceString());
tracingConnection.CommandFinished += (_, e) => traceSource.TraceInformation(e.ToFlattenedTraceString());
tracingConnection.CommandFailed += (_, e) => traceSource.TraceEvent(TraceEventType.Error, 0, e.ToFlattenedTraceString());
}
}