本文整理汇总了C#中System.Diagnostics.TraceListener.WriteLine方法的典型用法代码示例。如果您正苦于以下问题:C# TraceListener.WriteLine方法的具体用法?C# TraceListener.WriteLine怎么用?C# TraceListener.WriteLine使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Diagnostics.TraceListener
的用法示例。
在下文中一共展示了TraceListener.WriteLine方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ResilientMoveFile
/// <summary>
/// try, try, try... to move this file. tries for a predefined period, in case a very large file was copying, or times out
/// note: blocks thread
/// </summary>
/// <param name="sourcePath">full path to source file</param>
/// <param name="destinationPath">full path to destination file</param>
/// <param name="logFile">log file to write to</param>
/// <returns>true if file moved OK</returns>
public static bool ResilientMoveFile (string sourcePath, string destinationPath, TraceListener logFile)
{
if (logFile != null)
{
logFile.WriteLine ("Moving file '" + sourcePath + "' to '" + destinationPath + "'");
}
// it may have been created, but might not be finished copying. need to wait until we can have accessto move it
bool haveMoved = false;
int tryCount = 0;
DateTime timeStart = DateTime.Now;
while (!haveMoved)
{
// try to get access for predefined period
if (DateTime.Now - timeStart > TimeSpan.FromSeconds (EncoderFolderWatcherService.WatcherSettings.Default.retryFileCopyDurationSeconds))
{
throw new WatcherException (" Failed to get access to '" + sourcePath + "' within established time period -- abandoning");
}
// try renaming file. if we dont have access we will get the IOException
try
{
if (logFile != null)
{
logFile.WriteLine (" Trying to get access to '" + sourcePath + "'");
}
File.Move (sourcePath, destinationPath);
haveMoved = true;
if (logFile != null)
{
logFile.WriteLine (" Moved file '" + sourcePath + "' to '" + destinationPath + "'");
}
}
catch (FileNotFoundException)
{
// source file moved underneath us (someone else claimed?)
if (logFile != null)
{
logFile.WriteLine (" file '" + sourcePath + "' moved from underneath us. This machine should not do the encode");
}
return false;
}
catch (IOException)
{
// did not have access. Wait a little
if (logFile != null)
{
logFile.WriteLine (" Could not get access to '" + sourcePath + "' ... sleeping 1 second before retrying (try " + (++tryCount) + ")");
}
Thread.Sleep (1000);
}
}
return true;
}
示例2: OnConnection
/// <summary>
/// Implements the OnConnection method of the IDTExtensibility2 interface. Receives notification that the Add-in is being loaded.
/// </summary>
/// <param name='application'>
/// Root object of the host application.
/// </param>
/// <param name='connectMode'>
/// Describes how the Add-in is being loaded.
/// </param>
/// <param name='addIn'>
/// Object representing this Add-in.
/// </param>
/// /// <param name='custom'>
/// Array of parameters that are host application specific.
/// </param>
/// <seealso class='IDTExtensibility2' />
public void OnConnection(object application, ext_ConnectMode connectMode, object addIn, ref Array custom)
{
_application = (DTE2)application;
_addIn = (AddIn)addIn;
try
{
if (connectMode == ext_ConnectMode.ext_cm_Startup || connectMode == ext_ConnectMode.ext_cm_AfterStartup)
{
_listener = CreateTraceListener();
_env = new ControllerEnvironment(new WindowHandle(_application.MainWindow.HWnd), _listener);
_controller = CreateController();
_controller.OnConnectionStateChange += OnConnectionStateChange;
CreateCommands();
CreateToolWindow();
_listener.WriteLine("Addin initialized");
if (connectMode == ext_ConnectMode.ext_cm_AfterStartup)
{
OnStartupComplete(ref custom);
}
}
}
catch (Exception ex)
{
if (_listener != null)
{
_listener.WriteLine(ex);
}
}
}
示例3: OnOptionsSuccessful
private static void OnOptionsSuccessful(Options options, TraceListener tracer)
{
if (options.Help)
{
string helpText = CommandLine.Text.HelpText.AutoBuild(options);
tracer.WriteLine(helpText);
}
else
{
ILogger logger;
if (options.Verbose)
{
logger = new DateTimeLogger(tracer);
}
else
{
logger = VoidLogger.Default;
}
var ioOperations = new IoOperations(new FileSystem(), options.OutputPath, logger);
var generator = new Generator(options.StrictNullCheck);
var result = generator.Generate(options.Files, ioOperations);
ioOperations.Dump(result.Files);
}
}
示例4: Open
public static void Open(string logFolderPath, string logFileName, string prefix, Dictionary<ushort, string> sourceIDs)
{
logFolderPath = logFolderPath.TrimEnd(Path.DirectorySeparatorChar);
logFolderPath = logFolderPath.TrimEnd(Path.AltDirectorySeparatorChar);
if (sourceIDs == null)
{
throw new NullReferenceException();
}
if (sources == null || (currentLogPath != logFolderPath + Path.DirectorySeparatorChar + logFileName))
{
Close();
if (File.Exists(logFolderPath + Path.DirectorySeparatorChar + logFileName))
{
try
{
File.Delete(logFolderPath + Path.DirectorySeparatorChar + logFileName);
}
catch
{
}
}
//Console Normal
stdOut = new TextWriterTraceListener(new CLR_PSE_NativeLogger(false));
stdOut.Filter = new EventTypeFilter(consoleStdLevel); //information
stdOut.Name = "StdOut";
//Console Error
stdErr = new TextWriterTraceListener(new CLR_PSE_NativeLogger(true));
stdErr.Filter = new EventTypeFilter(consoleErrLevel);
stdErr.Name = "StdErr";
currentLogPath = logFolderPath + "\\" + logFileName;
//Text File
try
{
fileAll = new TextWriterTraceListener(currentLogPath);
fileAll.Filter = new EventTypeFilter(FileLevel);
fileAll.Name = "File";
//defualtSource.Listeners.Add(textListener);
}
catch (Exception e)
{
//Console.Error.WriteLine("Failed to Open Log File :" + e.ToString());
stdErr.WriteLine("Failed to Open Log File :" + e.ToString());
}
//Create sources
sources = new Dictionary<int, TraceSource>();
//Defualt Sources
AddSource(UNKOWN, "UnkownSource", prefix);
SetSourceLogLevel(SourceLevels.All, UNKOWN);
SetSourceUseStdOut(true, UNKOWN);
AddSource(ERRTRAP, "ErrorTrapper", prefix);
SetSourceUseStdOut(true, ERRTRAP);
foreach (KeyValuePair<ushort, string> sourceID in sourceIDs)
{
AddSource(sourceID.Key, sourceID.Value, prefix);
}
}
}
示例5: EncodeFile
/// <summary>
/// encode file to preset
/// </summary>
/// <param name="sourcePath">filepath to encode</param>
/// <param name="workingDirectory">working directory</param>
/// <param name="originalFilenameNoExt">original filename without extension</param>
/// <param name="presetPath">path to preset to use for this encoding</param>
/// <param name="logFile">logging file</param>
/// <returns>true if successful</returns>
private bool EncodeFile (string sourcePath, string workingDirectory, string originalFilenameNoExt, string presetPath, TraceListener logFile)
{
bool success = true;
string presetOutputDirectory = Path.Combine (this.directoryManager.OutputDirectory, Path.GetFileNameWithoutExtension (presetPath));
this.EncoderJob = new Job ();
try
{
logFile.WriteLine ("\r\n\r\n------------------------------------------------------------\r\n");
logFile.WriteLine ("Preset: " + Path.GetFileNameWithoutExtension (presetPath));
logFile.WriteLine ("Source: " + sourcePath);
Directory.CreateDirectory (presetOutputDirectory);
// encode
Preset preset = Preset.FromFile (presetPath);
MediaItem mediaItem = new MediaItem (sourcePath);
mediaItem.ApplyPreset (preset);
mediaItem.OutputFileName = "{Original file name}.Target.{Default extension}";
this.EncoderJob.MediaItems.Add (mediaItem);
this.EncoderJob.OutputDirectory = workingDirectory;
this.EncoderJob.CreateSubfolder = false;
this.EncoderJob.EncodeProgress += new EventHandler<EncodeProgressEventArgs> (this.Job_EncodeProgress);
this.EncoderJob.EncodeCompleted += new EventHandler<EncodeCompletedEventArgs> (this.Job_EncodeCompleted);
UserNotification.EncodingStarting (sourcePath + "->" + mediaItem.ActualOutputFileFullPath, EncodeInformation (mediaItem, "<br>"));
this.JobLog.WriteLine (EncodeInformation (mediaItem, "\r\n"));
if (this.EncodeStarted != null)
{
this.EncodeStarted (this, null);
}
this.EncoderJob.Encode ();
string outputSourcePath = Path.Combine (workingDirectory, mediaItem.ActualOutputFileName);
string outputTargetPath = Path.Combine (presetOutputDirectory, originalFilenameNoExt + Path.GetExtension (mediaItem.ActualOutputFileName));
Utilities.RenameFileMove (outputSourcePath, ref outputTargetPath, logFile);
logFile.WriteLine ("\r\n\r\nSuccess: Created Output file '" + outputTargetPath + "'");
if (this.EncodeEnded != null)
{
this.EncodeEnded (this, null);
}
}
catch (Exception ex)
{
logFile.WriteLine ("\r\n\r\nException: " + ex.Message);
success = false;
if (this.EncodeError != null)
{
this.EncodeError (this, null);
}
}
return success;
}
示例6: OutputSearchResult
public void OutputSearchResult(SearchResultCollection result, TraceListener listener)
{
int n = 0;
foreach (SearchResult sr in result)
{
listener.WriteLine(string.Format("第{0}行结果开始", n));
listener.IndentLevel++;
foreach (string propName in sr.Properties.PropertyNames)
{
string strValue = string.Empty;
for (int i = 0; i < sr.Properties[propName].Count; i++)
{
if (strValue != string.Empty)
strValue += ", ";
strValue += sr.Properties[propName][i].ToString();
}
listener.WriteLine(string.Format("Property Name: {0}\tProperty Value: {1}", propName, strValue));
}
listener.IndentLevel--;
listener.WriteLine(string.Format("第{0}行结果结束", n));
n++;
}
}
示例7: OutputEntryProperties
public void OutputEntryProperties(DirectoryEntry entry, TraceListener listener)
{
foreach (string strName in entry.Properties.PropertyNames)
{
listener.WriteLine(string.Format("Name: {0},\tValue: {1}", strName, entry.Properties[strName].Value.ToString()));
}
}
示例8: RetrieveDiagnostics
private static void RetrieveDiagnostics(DiagnosticView diagview, TraceListener traceListener)
{
// Display diagnostics for diagnostic view object
traceListener.WriteLine("Diagnostic View for '" + diagview.ObjectName + "':");
foreach (KeyValuePair<string, object> diagprop in diagview)
{
traceListener.WriteLine(" " + diagprop.Key + ": " + diagprop.Value);
}
}