本文整理汇总了C#中System.Diagnostics.TextWriterTraceListener类的典型用法代码示例。如果您正苦于以下问题:C# TextWriterTraceListener类的具体用法?C# TextWriterTraceListener怎么用?C# TextWriterTraceListener使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TextWriterTraceListener类属于System.Diagnostics命名空间,在下文中一共展示了TextWriterTraceListener类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: _Main
public static void _Main(string[] args)
{
Trace.WriteLine("start");
var logname = string.Format("{0}_{1}.{2}", "unhand", DateTime.Now.ToString("MMMdd-hhmmss-fffffff"), "log");
var listenerFile = new System.IO.FileInfo(logname);
listenerWriter = listenerFile.CreateText();
listener = new TextWriterTraceListener(listenerWriter);
Trace.Listeners.Add(listener);
//Trace.Listeners.Add(new TextWriterTraceListener(Console.Error));
Trace.AutoFlush = true;
AppDomain currentDomain = AppDomain.CurrentDomain;
currentDomain.UnhandledException += new UnhandledExceptionEventHandler(unhand_Handler);
try
{
Trace.WriteLine("throw 1");
throw new Exception("1");
}
catch (Exception e)
{
Trace.WriteLine($"Catch clause caught : {e.Message} \n");
}
Trace.WriteLine("throw 2");
throw new Exception("2");
//Trace.WriteLine("end");
}
开发者ID:MarcoDorantes,项目名称:spike,代码行数:28,代码来源:unhandled_exceptions.cs
示例2: MemoryTestHost
public MemoryTestHost(MemoryHost host, string logPath)
{
_host = host;
_listener = new TextWriterTraceListener(logPath + ".transports.log");
Disposables = new List<IDisposable>();
ExtraData = new Dictionary<string, string>();
}
开发者ID:hallco978,项目名称:SignalR,代码行数:7,代码来源:MemoryTestHost.cs
示例3: set_up
public void set_up()
{
Debug.Listeners.Clear();
TextWriterTraceListener t = new TextWriterTraceListener("log.txt");
Debug.Listeners.Add(t);
Debug.AutoFlush = true;
Debug.WriteLine("0");
/*PlatformID platformID = Environment.OSVersion.Platform;
if (platformID == PlatformID.Win32NT || platformID == PlatformID.Win32Windows) {
Process process = new Process();
process.StartInfo.FileName = "icepacknode";
process.StartInfo.Arguments = "--start FerdaIcePackNode";
process.Start();
process.WaitForExit();
}
else
{*/
ProcessStartInfo psi = new ProcessStartInfo("icegridnode", "--Ice.Config=config --IceGrid.Registry.Data=registry --IceGrid.Node.Data=node --deploy application.xml --warn");
psi.CreateNoWindow = true;
psi.WorkingDirectory = System.IO.Path.Combine(System.IO.Directory.GetCurrentDirectory(), "../db");
Process.Start(psi);
/*ProcessStartInfo psi2 = new ProcessStartInfo("icepackadmin", "--Ice.Config=config -e \"application add 'application.xml'\"");
psi2.CreateNoWindow = true;
Process processReg = Process.Start(psi2);
processReg.WaitForExit();*/
System.Threading.Thread.Sleep(5000);
/*}*/
Debug.WriteLine("1");
this.manager = new ModulesManager(new string[0],new string[2]{"cs-CZ","en-US"});
Debug.WriteLine("2");
}
开发者ID:BackupTheBerlios,项目名称:ferdadataminer-svn,代码行数:32,代码来源:ModulesManagerTest.cs
示例4: CreateDebugListener
private static void CreateDebugListener()
{
return;
string LogPath = System.Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\Viking\\Logs";
if (!Directory.Exists(LogPath))
Directory.CreateDirectory(LogPath);
string FileName = LogPath +"\\" + DateTime.Now.ToString("MM.dd.yyyy HH.mm.ss") + ".log";
DebugLogFile = System.IO.File.CreateText(FileName);
TextWriter SynchronizedDebugWriter = StreamWriter.Synchronized(DebugLogFile);
TextWriterTraceListener Listener = new TextWriterTraceListener(SynchronizedDebugWriter, "Viking Log Listener");
Trace.Listeners.Add(Listener);
Debug.Listeners.Add(Listener);
ConsoleTraceListener DebugOutputListener = new ConsoleTraceListener(true);
Trace.Listeners.Add(DebugOutputListener);
Debug.Listeners.Add(DebugOutputListener);
Trace.UseGlobalLock = true;
}
开发者ID:abordt,项目名称:Viking,代码行数:25,代码来源:Program.cs
示例5: GetFileList
/// <summary>
/// Return a dataset list given the name of the dataset.
/// </summary>
/// <param name="dsname"></param>
/// <returns></returns>
private static FileInfo[] GetFileList(string dsname)
{
TraceListener listener = null;
if (VerboseFileFetch)
{
listener = new TextWriterTraceListener(Console.Out);
Trace.Listeners.Add(listener);
}
try {
return GRIDJobs.FindJobFiles(JobName,
JobVersionNumber,
dsname,
nFiles: NFiles,
statusUpdate: l => Console.WriteLine(l),
intelligentLocal: true);
} finally
{
if (listener != null)
{
Trace.Listeners.Remove(listener);
}
}
}
开发者ID:gordonwatts,项目名称:JetCutStudies,代码行数:30,代码来源:Files.cs
示例6: Main
static void Main()
{
if (!EventLog.SourceExists("SelfMailer"))
{
EventLog.CreateEventSource("SelfMailer", "Mes applications");
}
EventLog eventLog = new EventLog("Mes applications", ".", "SelfMailer");
eventLog.WriteEntry("Mon message", EventLogEntryType.Warning);
BooleanSwitch booleanSwitch = new BooleanSwitch("BooleanSwitch", "Commutateur booléen.");
TraceSwitch traceSwitch = new TraceSwitch("TraceSwitch", "Commutateur complexe.");
TextWriterTraceListener textListener = new TextWriterTraceListener(@".\Trace.txt");
Trace.Listeners.Add(textListener);
Trace.AutoFlush = true;
Trace.WriteLineIf(booleanSwitch.Enabled, "Démarrage de l'application SelfMailer");
Project = new Library.Project();
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Forms.Main());
Trace.WriteLineIf(traceSwitch.TraceInfo, "Arrêt de l'application SelfMailer");
}
开发者ID:hugonjerome,项目名称:CSharp-5-Developpez-des-applications-Windows-avec-Visual-Studio-2012,代码行数:25,代码来源:Program.cs
示例7: CFile
// Create a constructor
public CFile()
{
// Add a new listener to the class
TextWriterTraceListener tr = new TextWriterTraceListener(System.Console.Out);
Debug.Listeners.Add(tr);
_sFileName = @Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\" + "CStudents.txt";
}
开发者ID:bfoote,项目名称:StudentInformation,代码行数:8,代码来源:CFile.cs
示例8: TraceTest01
public void TraceTest01()
{
Refresh("TraceClassTests_TextWriterTraceListener1");
try
{
using (FileStream fs = File.Create("TraceClassTests_TextWriterTraceListener1"))
{
TextWriterTraceListener textTL = new TextWriterTraceListener(fs);
Trace.Listeners.Add(textTL);
Trace.WriteLine("Message start.");
Trace.IndentSize = 2;
Trace.IndentLevel = 2;
Trace.Write("This message should be indented.");
Trace.TraceError("This error not be indented.");
Trace.TraceError("{0}", "This error is indendented");
Trace.TraceWarning("This warning is indented");
Trace.TraceWarning("{0}", "This warning is also indented");
Trace.TraceInformation("This information in indented");
Trace.TraceInformation("{0}", "This information is also indented");
Trace.IndentSize = 0;
Trace.IndentLevel = 0;
Trace.WriteLine("Message end.");
textTL.Dispose();
Assert.True(HelperMethods.CheckStrings("TraceClassTests_TextWriterTraceListener1", String.Format("Message start.\r\n This message should be indented.{0} Error: 0 : This error not be indented.\r\n {0} Error: 0 : This error is indendented\r\n {0} Warning: 0 : This warning is indented\r\n {0} Warning: 0 : This warning is also indented\r\n {0} Information: 0 : This information in indented\r\n {0} Information: 0 : This information is also indented\r\nMessage end.\r\n", "DEFAULT_APPNAME"))); //DEFAULT_APPNAME this a bug which needs to be fixed.
}
}
finally
{
Refresh("TraceClassTests_TextWriterTraceListener1");
}
}
开发者ID:gitter-badger,项目名称:corefx,代码行数:33,代码来源:TraceClassTests.cs
示例9: CorrelationIdTestAsync
public static async Task CorrelationIdTestAsync(Sts sts)
{
SetCredential(sts);
var context = new AuthenticationContextProxy(sts.Authority, sts.ValidateAuthority);
Guid correlationId = Guid.NewGuid();
AuthenticationResultProxy result = null;
MemoryStream stream = new MemoryStream();
using (var listener = new TextWriterTraceListener(stream))
{
Trace.Listeners.Add(listener);
context.SetCorrelationId(correlationId);
result = context.AcquireToken(sts.ValidResource, sts.ValidClientId, sts.ValidDefaultRedirectUri, PromptBehaviorProxy.Auto, sts.ValidUserId);
VerifySuccessResult(sts, result);
listener.Flush();
string trace = Encoding.UTF8.GetString(stream.ToArray(), 0, (int)stream.Position);
Verify.IsTrue(trace.Contains(correlationId.ToString()));
Trace.Listeners.Remove(listener);
}
stream = new MemoryStream();
using (var listener = new TextWriterTraceListener(stream))
{
Trace.Listeners.Add(listener);
context.SetCorrelationId(Guid.Empty);
AuthenticationResultProxy result2 = await context.AcquireTokenByRefreshTokenAsync(result.RefreshToken, sts.ValidClientId);
Verify.IsNotNull(result2.AccessToken);
listener.Flush();
string trace = Encoding.UTF8.GetString(stream.ToArray(), 0, (int)stream.Position);
Verify.IsFalse(trace.Contains(correlationId.ToString()));
Verify.IsTrue(trace.Contains("Correlation ID"));
Trace.Listeners.Remove(listener);
}
}
开发者ID:jpda,项目名称:azure-activedirectory-library-for-dotnet,代码行数:35,代码来源:AdalTests2.cs
示例10: VisualLog
public static void VisualLog(LogLevels loglevel, string type, String ex)
{
// create output to console
TextWriterTraceListener console = new TextWriterTraceListener();
console.Writer = Console.Out;
Trace.Listeners.Add(console);
//output error
if (System.Diagnostics.Trace.Listeners.Count > 0)
{
Trace.Write(new TraceData(loglevel, DateTime.Now, type, ex));
}
//close streams
console.Close();
if (!ApplicationType.GetApplicationType().Equals(ApplicationType.Type.Console))
{
//messagebox
MessageBoxIcon icon = MessageBoxIcon.None;
switch (loglevel)
{
case LogLevels.Error:
icon = MessageBoxIcon.Error;
break;
case LogLevels.Warning:
icon = MessageBoxIcon.Warning;
break;
case LogLevels.Info:
icon = MessageBoxIcon.Information;
break;
}
MessageBox.Show(ex, type, MessageBoxButtons.OK, icon);
}
}
开发者ID:b1thunt3r,项目名称:bitLibCS_old,代码行数:33,代码来源:HandleLog.cs
示例11: WorkflowTrace
static WorkflowTrace()
{
runtime.Switch = new SourceSwitch("System.Workflow.Runtime", SourceLevels.Off.ToString());
tracking = new TraceSource("System.Workflow.Runtime.Tracking");
tracking.Switch = new SourceSwitch("System.Workflow.Runtime.Tracking", SourceLevels.Off.ToString());
host = new TraceSource("System.Workflow.Runtime.Hosting");
host.Switch = new SourceSwitch("System.Workflow.Runtime.Hosting", SourceLevels.Off.ToString());
BooleanSwitch switch2 = new BooleanSwitch("System.Workflow LogToFile", "Log traces to file");
if (switch2.Enabled)
{
TextWriterTraceListener listener = new TextWriterTraceListener("WorkflowTrace.log");
Trace.Listeners.Add(listener);
runtime.Listeners.Add(listener);
host.Listeners.Add(listener);
}
BooleanSwitch switch3 = new BooleanSwitch("System.Workflow LogToTraceListeners", "Trace to listeners in Trace.Listeners", "0");
if (switch3.Enabled)
{
foreach (TraceListener listener2 in Trace.Listeners)
{
if (!(listener2 is DefaultTraceListener))
{
runtime.Listeners.Add(listener2);
tracking.Listeners.Add(listener2);
host.Listeners.Add(listener2);
}
}
}
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:29,代码来源:WorkflowTrace.cs
示例12: Main
public static void Main(string[] args)
{
var listener = new TextWriterTraceListener(Console.Out);
Trace.Listeners.Add(listener);
launchApp();
}
开发者ID:chakrit,项目名称:toast,代码行数:7,代码来源:Program.cs
示例13: Initialize
public void Initialize()
{
try
{
// service hosts need to be started in a particular order, before everything else
//DatabaseNotificationManagerServiceHost.Instance.Start();
//LoggerWCFTraceListenerServiceHost.Instance.Start();
if (LicenseManager.Instance.LoggingEnabled)
{
Logger.TraceSwitch.Level = LicenseManager.Instance.TraceLevel;
Trace.AutoFlush = true;
var logFile = new FileInfo(Utility.LogFilePath);
if (!logFile.Directory.Exists)
logFile.Directory.Create();
var listener =
new TextWriterTraceListener(Utility.LogFilePath) { Name = ServiceName + "Trace" };
//Trace.Listeners.Clear();
Trace.Listeners.Add(listener);
}
// create service agents
Agents = new List<IServiceAgent>
{
new Converter.Agent.Agent(),
new DlnaDownloader.Agent.Agent()
};
}
catch (Exception exception)
{
Utility.EmergencyWriteEventLog(exception.Message);
Logger.TraceErr(exception);
}
}
开发者ID:CarverLab,项目名称:tubeCentricService.root,代码行数:34,代码来源:Loader.cs
示例14: Main
/// <summary>
/// Main Execution. UI handled in separate method, as this is a procedural utility.
/// </summary>
/// <param name="args">Not used</param>
private static void Main(string[] args)
{
string serverUrl, destProjectName, plansJSONPath, logPath, csvPath;
UIMethod(out serverUrl, out destProjectName, out plansJSONPath, out logPath, out csvPath);
teamCollection = new TfsTeamProjectCollection(new Uri(serverUrl));
workItemStore = new WorkItemStore(teamCollection);
Trace.Listeners.Clear();
TextWriterTraceListener twtl = new TextWriterTraceListener(logPath);
twtl.Name = "TextLogger";
twtl.TraceOutputOptions = TraceOptions.ThreadId | TraceOptions.DateTime;
ConsoleTraceListener ctl = new ConsoleTraceListener(false);
ctl.TraceOutputOptions = TraceOptions.DateTime;
Trace.Listeners.Add(twtl);
Trace.Listeners.Add(ctl);
Trace.AutoFlush = true;
// Get Project
ITestManagementTeamProject newTeamProject = GetProject(serverUrl, destProjectName);
// Get Test Plans in Project
ITestPlanCollection newTestPlans = newTeamProject.TestPlans.Query("Select * From TestPlan");
// Inform user which Collection/Project we'll be working in
Trace.WriteLine("Executing alignment tasks in collection \"" + teamCollection.Name
+ "\",\n\tand Destination Team Project \"" + newTeamProject.TeamProjectName + "\"...");
// Get and print all test case information
GetAllTestPlanInfo(newTestPlans, plansJSONPath, logPath, csvPath);
Console.WriteLine("Alignment completed. Check log file in:\n " + logPath
+ "\nfor missing areas or other errors. Press enter to close.");
Console.ReadLine();
}
开发者ID:Ryanman,项目名称:CustomTools.AlignMigration,代码行数:38,代码来源:AlignMigration.cs
示例15: Form_Main
string _test_error_msg; // If set this will indicate error for tests usually run after calibration
#endregion Fields
#region Constructors
/// <summary>
/// The main form constructor
/// </summary>
public Form_Main()
{
// Init the trace listener
try
{
Stream outResultsFile = File.Create("output.txt");
var textListener = new TextWriterTraceListener(outResultsFile);
Trace.Listeners.Add(textListener);
}
catch (System.IO.IOException)
{
// Most likely we are already running
MessageBox.Show("Unable to open trace listener.\r\n\"" + this.assemblyTitle + "\" may already be running?\r\nExiting...", this.assemblyTitle);
this.Close();
}
InitializeComponent();
// Create the app data folder
if (!Directory.Exists(_app_data_dir))
{
Directory.CreateDirectory(_app_data_dir);
}
// Init the log file
initLogFile();
}
开发者ID:VicsWork,项目名称:PowerCalibration,代码行数:35,代码来源:Form_Main.cs
示例16: Main
/// <summary>
/// Constructor
/// </summary>
static void Main(string[] args)
{
Debug.AutoFlush = true;
Debug.IndentLevel = 0;
// Write to CLI also
TextWriterTraceListener writer = new TextWriterTraceListener(System.Console.Out);
Debug.Listeners.Add(writer);
run = new WinLLDP();
// Send first packet immediately
sendPacket();
// Run the LLDP packet sender every X seconds
Debug.WriteLine("Starting timer", EventLogEntryType.Information);
timer.Interval = TimeSpan.FromSeconds(10).TotalMilliseconds;
timer.AutoReset = true;
timer.Elapsed += triggerEvent;
timer.Start();
// Wait for keypress
Debug.WriteLine("Press key to stop", EventLogEntryType.Information);
Console.ReadKey();
timer.Stop();
}
开发者ID:raspi,项目名称:WinLLDPService,代码行数:30,代码来源:CLI.cs
示例17: Main
/// <summary>
/// The main entry point for the application.
/// </summary>
private static void Main(string [] args)
{
var service = new RRLightService();
if (Environment.UserInteractive)
{
// Application runs as an independent program (e.g. from console), but not as Windows service.
// As this project uses Windows Form application as the base, it cannot run as console application.
// Instead, all messages will be redirected to log file in "Logs" subcirectory.
DirectoryInfo currentDirectory = new DirectoryInfo(Directory.GetCurrentDirectory());
DirectoryInfo logsDirectory = currentDirectory.CreateSubdirectory("Logs");
var listner = new TextWriterTraceListener(
Path.Combine(logsDirectory.FullName, string.Format("RRLightServiceDebug-{0:yy-MM-dd-HH-mm}.log", DateTime.UtcNow)));
listner.TraceOutputOptions |= TraceOptions.DateTime;
Trace.Listeners.Add(listner);
Trace.AutoFlush = true;
// Always enable verbose trace.
TraceVerbose.Enabled = true;
service.ManualRun();
}
else
{
// Send trace messages to Event Log.
var listner = new EventLogTraceListener("PanoptoRRLightService");
Trace.Listeners.Add(listner);
// Enable verbose trace if config is set.
TraceVerbose.Enabled = Properties.Settings.Default.EnableVerboseTrace;
ServiceBase.Run(new ServiceBase[] { service });
}
}
开发者ID:uw-it-cte,项目名称:Panopto-RR-Light-Service-With-Installer,代码行数:38,代码来源:Program.cs
示例18: ClassInitialze
public static void ClassInitialze()
{
TextWriterTraceListener tr1 = new TextWriterTraceListener(System.Console.Out);
// Initialize default log factory
// LoggerFactory.SetCurrent(new TraceSourceLogFactory(tr1));
LoggerFactory.SetCurrent(new TraceSourceLogFactory());
}
开发者ID:jiguixin,项目名称:MyLibrary,代码行数:7,代码来源:TraceSourceLogTests.cs
示例19: Test03
public void Test03()
{
string msg1, name;
name = "MyXMLTraceWriter";
string fileName = string.Format("{0}_3.xml", this.GetType().Name);
//Testing ctor(Stream, string)
//Scenario 3: Vanilla - Pass in a valid name and check with the Name property
try
{
CommonUtilities.DeleteFile(fileName);
_stream = new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.Write);
_textWriter = new TextWriterTraceListener(_stream, name);
Assert.True(_textWriter.Name == name);
msg1 = "HelloWorld";
_textWriter.WriteLine(msg1);
_textWriter.Dispose();
Assert.True(CommonUtilities.TestListenerContent(new Type[] { typeof(TextWriterTraceListener) }, new string[] { fileName }, msg1));
}
finally
{
CommonUtilities.DeleteFile(fileName);
}
}
开发者ID:gitter-badger,项目名称:corefx,代码行数:25,代码来源:CtorsStreamTests.cs
示例20: Main
static void Main(string[] args)
{
var directory = args.Length == 0 ? "." : args[0];
directory = directory.EndsWith("\\") ? directory : directory + "\\";
TextWriterTraceListener log = null;
try
{
using (var filestream = new FileStream(directory + "log.csv", FileMode.Create, FileAccess.Write, FileShare.Read))
{
log = new TextWriterTraceListener(filestream);
foreach (var file in new DirectoryInfo(directory).GetFiles().Select(file => file.Name))
{
var begin = DateTime.Now;
using (var source = new Bitmap(Image.FromFile(file)))
{
using (var bm = ConvertToGrayscale(source))
{
bm.Save(string.Format("{0}{1}.{2}", directory, "gray", file));
}
}
var end = DateTime.Now;
log.WriteLine(string.Format("{0},gray.{0},{1}", file, end - begin));
log.Flush();
}
}
}
catch (Exception ex)
{
log.WriteLine(ex.Message);
log.WriteLine(ex.StackTrace);
}
}
开发者ID:markdrichter,项目名称:grayscale,代码行数:34,代码来源:Program.cs
注:本文中的System.Diagnostics.TextWriterTraceListener类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论