本文整理汇总了C#中System.IO.FileInfo.AppendText方法的典型用法代码示例。如果您正苦于以下问题:C# FileInfo.AppendText方法的具体用法?C# FileInfo.AppendText怎么用?C# FileInfo.AppendText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.FileInfo
的用法示例。
在下文中一共展示了FileInfo.AppendText方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: writeToFile
static void writeToFile(string text)
{
FileInfo logFile;
int day, month, year;
day = DateTime.Now.Day;
month = DateTime.Now.Month;
year = DateTime.Now.Year;
string fileName = "Logger_" + day + "_" + month + "_" + year;
logFile = new FileInfo(HostingEnvironment.ApplicationPhysicalPath + @".\Logs\" + fileName);
if (!logFile.Exists)
{
using(StreamWriter sw = logFile.CreateText())
{
sw.WriteLine(DateTime.Now + " : " + text);
}
}
else
{
using(StreamWriter sw = logFile.AppendText())
{
sw.WriteLine(DateTime.Now + " : " + text);
}
}
}
示例2: SaveToFile
public void SaveToFile(string fileName)
{
var file = new FileInfo(@fileName);
var stream = file.AppendText();
this.WriteFactors(stream);
stream.Close();
}
示例3: PrintGErrs
/*
* FOR DEBUG ONLY
*/
internal void PrintGErrs(int indGlyph)
{
FileInfo infoFile=new FileInfo("GERRS.txt");
StreamWriter writer=infoFile.AppendText();
writer.WriteLine("===> GLYPH "+indGlyph);
GErrList gerrlist=this.gerrlists[indGlyph] as GErrList;
if (gerrlist!=null)
{
writer.WriteLine("NUMBER of ERRORS: "+gerrlist.Length);
}
else
{
writer.WriteLine("EMPTY LIST");
writer.Close();
return;
}
foreach (GErr gerr in gerrlist)
{
string str=gerr.Write();
writer.WriteLine("");
writer.WriteLine("Error: ");
writer.Write(str);
}
writer.Close();
}
示例4: LogError
/// <summary>
/// Log an error to the log file
/// </summary>
/// <param name="toLog">The error text to log</param>
internal static void LogError(string toLog)
{
// Should this be logged?
if(Log)
{
StreamWriter sw = null;
try
{
// We want to open the file and append some text to it
FileInfo file = new FileInfo(logFile);
sw = file.AppendText();
sw.WriteLine(DateTime.Now);
sw.WriteLine(toLog);
sw.WriteLine();
sw.Flush();
}
finally
{
if(sw != null)
{
sw.Close();
}
}
}
}
示例5: FileTelemetryConsumer
public FileTelemetryConsumer(FileInfo file)
{
_logFileName = file.FullName;
var fileExists = File.Exists(_logFileName);
_logOutput = fileExists ? file.AppendText() : file.CreateText();
file.Refresh();
}
示例6: Log
public static void Log(string content)
{
FileInfo logFile = new FileInfo(GetDataFile("log.txt"));
using (StreamWriter logStream = logFile.AppendText())
logStream.Write(DateTime.Now.ToLongTimeString() + content + "\r\n");
}
示例7: escreverFicheiro
/*
* Método que cria o ficheiro, se ainda não
* existir, se existir, vai acrescentar ao ficheiro
* o que for enviado para o ficheiro através
* da variavél que recebe, a menssagem.
* */
public void escreverFicheiro(string menssagem)
{
FileInfo file = new FileInfo("EstatisticaLP_C#.txt");
StreamWriter Txt = file.AppendText();
Txt.WriteLine(menssagem);
Txt.Close();
}
示例8: Log
public void Log(String src, String message)
{
FileInfo file = new FileInfo(src);
StreamWriter sw = file.AppendText();
sw.WriteLine(message);
sw.Close();
}
示例9: Main
static void Main(string[] args)
{
var sourceFile = new System.IO.FileInfo(@"C:\Users\pasca\Desktop\voc-it.mdb");
var stenoEntries = Converter.Parse(sourceFile);
var filtered = stenoEntries.GroupBy(_s => _s.WinstenoStroke).Select(_g => _g.First());
Console.WriteLine("Loaded {0} entries from {1}, {2} after duplicates removal.", stenoEntries.Count(), sourceFile.Name, filtered.Count());
foreach (var duplicates in stenoEntries.GroupBy(_s => _s.WinstenoStroke).Where(_g => _g.Count() > 1))
{
Console.WriteLine("Duplicate : {0}", duplicates.Key);
foreach(var dup in duplicates)
{
Console.WriteLine("\t{0} - {1}", dup.Complete, dup.Partial);
}
}
var ploverEntries = filtered.SelectMany(_se => PloverEntry.FromWinstenoEntry(_se)).Where(_pe=>_pe != null);
var plovedFiltered = ploverEntries.GroupBy(_s => _s.Strokes.ToString()).Select(_g => _g.First());
var outFile = new FileInfo(String.Format("{0}.json", Path.GetFileNameWithoutExtension(sourceFile.FullName)));
outFile.Delete();
using (var outstream = outFile.AppendText())
{
outstream.Write("{\n");
foreach (var entry in plovedFiltered)
{
outstream.Write("\"{0}\": \"{1}\", \n", entry.Strokes, entry.Value);
}
outstream.Write("\"\": \"\"\n");
outstream.Write("}");
}
Console.WriteLine("Written {0} entries in {1}", plovedFiltered.Count(), outFile.FullName);
}
示例10: WriteLog
public string WriteLog(string s)
{
try
{
FileInfo fi = new FileInfo("J:\\_net\\sys.log");
StreamWriter sw;
if (fi.Exists)
sw = fi.AppendText();
else
sw = fi.CreateText();
sw.WriteLine(s + "\r\n");
sw.Close();
}
catch (IOException ex)
{
return "IO Error";
}
catch (UnauthorizedAccessException ex)
{
return "Unauthorized Access";
}
catch (SecurityException ex)
{
return "Security Error";
}
catch (NotSupportedException ex)
{
return "not supported";
}
return "Hello World";
}
示例11: Write
public void Write(string content)
{
try
{
if (!Directory.Exists(_filePath))
{
Directory.CreateDirectory(_filePath);
}
if (_fileName.IndexOf("/", StringComparison.Ordinal) != -1)
{
_fileName = _fileName.Replace("/", "-");
}
string strLogName = _filePath + "\\" + _fileName;
var logFile = new FileInfo(strLogName);
var textFile = logFile.AppendText();
//如果日志文件大于50M
if (logFile.Length < 50000000)
{
textFile.WriteLine(content);
}
textFile.Close();
}
catch (Exception ex)
{
//
}
}
示例12: OutputLogToFile
private static void OutputLogToFile(int type, string tag, string message)
{
#if UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX
switch (type)
{
case LOG_TYPE_INFO:
tag = "I: " + tag;
break;
case LOG_TYPE_WARNING:
tag = "W: " + tag;
break;
case LOG_TYPE_ERROR:
tag = "E: " + tag;
break;
}
StreamWriter sw;
FileInfo t = new FileInfo(Application.dataPath + "//Log.txt");
if (!t.Exists)
{
sw = t.CreateText();
}
else
{
sw = t.AppendText();
}
sw.WriteLine(tag + message);
sw.Close();
sw.Dispose();
#endif
}
示例13: PrintF
public static void PrintF(String line)
{
String day = DateTime.Now.ToString("yyyyMMdd");
FileInfo fileInfo = new FileInfo(Config.GetPath() + "log_"+ day + ".log");
// Console.WriteLine("PrintF");
/*
음 이것도.. UI 쓰레드에서 돌리면 부하가 걸리는구나..
그럼 결국엔.. 이것도.. 큐에 넣었다가
쓰레드로 파일에 쓰는 작업을 해야겠네..
*/
lock (locker)
{
/*
String tmp1 = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
line = "[" + tmp1 + "]" + line;
System.IO.StreamWriter file = new System.IO.StreamWriter(path, true);
file.WriteLine(line);
file.Close();
*/
String tmp1 = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
line = "[" + tmp1 + "]" + line;
using (StreamWriter FileWriter = fileInfo.AppendText())
{
FileWriter.WriteLine(line);
}
}
/* 오히려 쓰레드가 더 느리네.. 쓰레드 삭제.
Thread t1 = new Thread(() => WirteFile(line));
t1.Start();
*/
}
示例14: LogSingleEvent
public static void LogSingleEvent(string logIndicationText)
{
StreamWriter strm;
string logFileName;
string workdir = ConfigurationManager.AppSettings["DirectorioTrabajo"];
logFileName = String.Concat(workdir,
ConfigurationManager.AppSettings["LogFileNameFormat"]);
FileInfo archivo = new FileInfo(logFileName);
DateTime yesterday = DateTime.Now.Subtract(new TimeSpan(1, 0, 0, 0, 0));
if (archivo.Exists)
{
if (String.Compare(archivo.LastWriteTime.ToString("yyyyMMdd"), yesterday.ToString("yyyyMMdd")) < 0)
{
archivo.Delete();
strm = archivo.CreateText();
}
else
{
strm = archivo.AppendText();
}
}
else
strm = archivo.CreateText();
strm.WriteLine(String.Format("{0} - {1}",
DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.ffff"), logIndicationText));
strm.Close();
}
示例15: BitWriter
/// <summary>
/// Inicializa el archivo tambien para su escritura
/// </summary>
public BitWriter(string workdir)
{
string logFileName;
logFileName = String.Concat(workdir,
ConfigurationManager.AppSettings["LogFileNameFormat"]);
FileInfo archivo = new FileInfo(logFileName);
DateTime yesterday = DateTime.Now.Subtract(new TimeSpan(1, 0, 0, 0, 0));
if (archivo.Exists)
{
if (String.Compare(archivo.LastWriteTime.ToString("yyyyMMdd"), yesterday.ToString("yyyyMMdd")) < 0)
{
archivo.Delete();
logStream = archivo.CreateText();
}
else
{
logStream = archivo.AppendText();
}
}
else
logStream = archivo.CreateText();
logStream.WriteLine(String.Format("--- Inicio de control {0} ---",
DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.ffff")));
}