本文整理汇总了C#中System.Diagnostics.TraceSource.TraceInformation方法的典型用法代码示例。如果您正苦于以下问题:C# TraceSource.TraceInformation方法的具体用法?C# TraceSource.TraceInformation怎么用?C# TraceSource.TraceInformation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Diagnostics.TraceSource
的用法示例。
在下文中一共展示了TraceSource.TraceInformation方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RunSampleAsync
private static async Task RunSampleAsync(CleanupGuard guard, TraceSource traceSource, CancellationToken token)
{
// Make sure we switch to another thread before starting the work.
await Task.Yield();
string timestamp = DateTime.Now.ToString("yyyyMMhhmmss");
string filePrefix = Environment.ExpandEnvironmentVariables(@"%TEMP%\CleanupSample." + timestamp + ".");
Random random = new Random();
char[] alphabet = new char[] { 'z', 'x', 'c', 'v', 'b', 'n', 'm' };
int index = 0;
while (!token.IsCancellationRequested)
{
string fileName = filePrefix + index + ".txt";
guard.Register(() => ZeroFileAsync(fileName, traceSource));
traceSource.TraceInformation("Writing file '{0}'...", fileName);
await WriteFileAsync(fileName, random, alphabet, token);
traceSource.TraceInformation("Starting 'notepad.exe {0}'...", fileName);
Process process = Process.Start("notepad.exe", fileName);
guard.Register(Blocking.Task(KillProcess, Tuple.Create(process, traceSource)));
traceSource.TraceInformation("Waiting...");
await Task.Delay(3000, token);
++index;
}
}
示例2: Main
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
var ts = new TraceSource("rskb.application", SourceLevels.All);
var di = new SimpleInjector.Container();
ts.TraceInformation("Build");
var blackboxfolderpath = ConfigurationManager.AppSettings["blackboxfolderpath"];
di.RegisterSingle<IBlackBox>(() => new FileBlackBox(blackboxfolderpath));
di.RegisterSingle(typeof (IBoardPortal), typeof (BoardPortal));
di.RegisterSingle(typeof(IBoardProvider2), typeof(EventstoreBoardprovider));
di.RegisterSingle(typeof(IBoard2), typeof(Board2));
di.RegisterSingle(typeof (IBoardController), typeof (BoardController2));
var prov = di.GetInstance<IBoardProvider2>();
var portal = di.GetInstance<IBoardPortal>();
var ctl = di.GetInstance<IBoardController>();
ts.TraceInformation("Bind");
portal.On_card_moved += ctl.Move_card;
portal.On_new_card += ctl.Create_card;
portal.On_refresh += ctl.Refresh;
ctl.On_cards_changed += portal.Display_cards;
ts.TraceInformation("Run");
Start(prov, portal);
ts.TraceInformation("Show");
Application.Run(portal as Form);
}
示例3: HybridAgent
/// <summary>
/// The Agent checks for pending notifications and delivers them to the proper Transport.
/// Hybrid Agent uses DB (entity) access for the data model.
/// Transport calls are made by web service.
///
/// Modifed: 2009-11-1, Jeremy Richardson
/// -Fixed issues with local FS when running as a service
/// -Added extra exception handling/logging for more robust Service operation
///
/// Modified: 2010-08-30, John Morgan
/// -Changed agent to utilize System.Threading.Timer as opposed to System.Timers.Timer due to exception swallowing
/// </summary>
public HybridAgent()
{
string traceName = this.GetType().FullName;
Trace.WriteLine(string.Format("Registering Trace Source {0}.", traceName));
_Tracer = new TraceSource(traceName);
System.IO.Directory.SetCurrentDirectory(System.AppDomain.CurrentDomain.BaseDirectory);
_Tracer.TraceInformation("Current Directory Set To {0}", System.IO.Directory.GetCurrentDirectory().ToString());
if (DateTime.Now.TimeOfDay < Settings.Default.ReminderTime.TimeOfDay)
_LastReminderNotification = DateTime.Now - new TimeSpan(1, 0, 0, 0);
else
_LastReminderNotification = DateTime.Now;
_Tracer.TraceInformation(this.GetType().Assembly.GetName().Version.ToString());
string configValues = "\r\n---Configuration---";
configValues += string.Format("Enable Escalation: {0}\r\n", Settings.Default.EnableEscalation);
configValues += string.Format("Enable Notification: {0}\r\n", Settings.Default.EnableNotification);
configValues += string.Format("Enable Reminder: {0}\r\n", Settings.Default.EnableReminder);
configValues += string.Format("Escalation Repeat Timeout: {0}\r\n", Settings.Default.EscalationRepeatTimeout);
configValues += string.Format("Escalation Transport Name: {0}\r\n", Settings.Default.EscalationTransportName);
configValues += string.Format("Critical Results URI: {0}\r\n", Settings.Default.CriticalResultsUri);
configValues += string.Format("Reminder Time: {0}\r\n", Settings.Default.ReminderTime);
configValues += string.Format("Reminder Transport: {0}\r\n", Settings.Default.ReminderTransportName);
configValues += string.Format("Timer Interval: {0}\r\n", Settings.Default.TimerInterval);
configValues += "---Configuration End---";
_Tracer.TraceInformation(configValues);
System.Threading.TimerCallback timerCallback = this.OnTimerElapsed;
_Timer = new System.Threading.Timer(timerCallback, null, 0, _TimerInterval);
//_Timer.Interval = Settings.Default.TimerInterval.TotalMilliseconds;
//_Timer.Elapsed += new ElapsedEventHandler(OnTimerElapsed);
//_Timer.Start();
}
示例4: SimpleEmailer
public SimpleEmailer(string host, int port, string userName, string password, string domain, bool useSsl, string fromAddress, string fromName)
{
string traceName = this.GetType().FullName;
Trace.WriteLine(string.Format("Creating TraceSource {0}. Please register a listener for detailed information.", traceName));
_Trace = new TraceSource(traceName);
_Trace.TraceInformation("Creating SmtpTransport: UserName:{0}, Password: -, Domain:{1}, Host:{2}, Port:{3}, SSL:{4}", userName, domain, host, port, useSsl);
_Client = new SmtpClient(host,port);
_Trace.TraceInformation("Created SMTP Client - {0}:{1}", host, port);
_Client.EnableSsl = useSsl;
_From = new MailAddress(fromAddress, fromName);
_Trace.TraceInformation("From address set to {0} [{1}]", _From.Address, _From.DisplayName);
if (!string.IsNullOrEmpty(userName))
{
_Client.UseDefaultCredentials = false;
_Client.Credentials = new System.Net.NetworkCredential(userName, password, domain);
_Trace.TraceInformation("Created credentials for {0}\\{1}", domain, userName);
}
else
{
_Client.UseDefaultCredentials = true;
_Trace.TraceInformation("Using default credentials");
}
}
示例5: 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());
}
}
示例6: Tracing
public Tracing(TraceSource traceSource, string name)
{
_traceSource = traceSource;
_name = name;
_traceSource.TraceInformation(string.Format("Entering {0}", _name));
}
示例7: CreateSource
static TraceSource CreateSource(string name)
{
var source = new TraceSource(name);
// The source.Listeners.Count call causes the tracer to be initialized from config at this point.
source.TraceInformation("Initialized trace source {0} with initial level {1} and {2} initial listeners.", name, source.Switch.Level, source.Listeners.Count);
return source;
}
示例8: ConfigTest
public void ConfigTest()
{
var source = new TraceSource("MSMQTEST", SourceLevels.All);
source.TraceInformation("test1");
source.TraceEvent(TraceEventType.Error, 1, "Test 2 {0}", 123);
}
示例9: ZeroFileAsync
private static async Task ZeroFileAsync(string fileName, TraceSource traceSource)
{
traceSource.TraceInformation("Zeroing out file '{0}'...", fileName);
using (FileStream stream = CreateAsyncStream(fileName))
{
await stream.WriteAsync(new byte[0], 0, 0);
}
}
示例10: Application_Start
public void Application_Start(object sender, EventArgs e)
{
Trace = new TraceSource("Global", SourceLevels.All);
Trace.Listeners.Add(SignalRTraceListener);
Storage.Trace.Listeners.Add(SignalRTraceListener);
RouteTable.Routes.MapHubs();
Trace.TraceInformation("Application Starting");
}
示例11: TraceStack
public static void TraceStack(TraceSource file)
{
StackTrace stackTrace = new StackTrace();
if (file != null && stackTrace.FrameCount > 0)
{
file.TraceInformation("_________________________________________");
file.TraceInformation("StackTrace:");
for (int i = 0; i < stackTrace.FrameCount; i++)
{
string frame = string.Empty;
if (stackTrace.GetFrame(i).GetMethod() != null && stackTrace.GetFrame(i).GetMethod().DeclaringType != null)
{
frame = "\t" + stackTrace.GetFrame(i).GetMethod().DeclaringType.ToString() +
"." + stackTrace.GetFrame(i).GetMethod().Name;
//file.TraceInformation("." + stackTrace.GetFrame(i).GetMethod().Name);
ParameterInfo[] parameters = stackTrace.GetFrame(i).GetMethod().GetParameters();
if (parameters != null && parameters.Length > 0)
{
frame += "( ";
foreach (ParameterInfo pi in parameters)
{
frame += pi.ParameterType + " " + pi.Name + ", ";
}
frame += " )";
}
file.TraceInformation(frame);
file.TraceInformation("");
}
}
file.TraceInformation("_________________________________________");
}
}
示例12: 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();
}
示例13: 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();
}
示例14: CanLogFromTraceSourceInformation
public void CanLogFromTraceSourceInformation()
{
var logMessage = "a simple message";
var traceSource = new TraceSource("test", SourceLevels.All);
traceSource.Listeners.Clear();
traceSource.Listeners.Add(_traceListener);
traceSource.TraceInformation(logMessage);
LogEventAssert.HasLevel(LogEventLevel.Information, _loggedEvent);
LogEventAssert.HasPropertyValue(logMessage, "TraceMessage", _loggedEvent);
}
示例15: ConnectDiagnosticListeners
private void ConnectDiagnosticListeners()
{
Console.WriteLine("Trying to connect to the System.ServiceModel trace source.");
traceListener = new ConsoleTraceListener(false);
TraceSource serviceModelTraceSource = new TraceSource("System.ServiceModel");
serviceModelTraceSource.Listeners.Add(traceListener);
serviceModelTraceSource.TraceInformation("Test information from the host form \r\n");
TraceSource commonTraceSource = new TraceSource("Tools.Common");
commonTraceSource.Listeners.Add(traceListener);
commonTraceSource.TraceInformation("Test information from the Tools.Common \r\n");
}