public FileAppender(ILayout layout, IWritableObject file) : base(layout, file) { if (!(file is IWritableFile)) { throw new ArgumentException("The given WritableObject MUST Implement IWritableFile!"); } }
/// <summary> /// Writes to a file the given text /// </summary> /// <param name="writeable">Writable object to write to file</param> /// <param name="filePath">Complete path to save file into. (Without filename)</param> /// <returns></returns> public bool ToWriteFile(IWritableObject writeable, string filePath) { string fullFilePath = Path.Combine(filePath, writeable.FileName); try { if (string.IsNullOrEmpty(fullFilePath)) { return(false); } if (!fullFilePath.Contains(".")) { return(false); } if (writeable.GetLines() == null) { return(false); } File.WriteAllLines(fullFilePath, writeable.GetLines()); return(true); } catch (Exception e) { Console.WriteLine("Error: " + e); return(false); } }
/// <summary> /// Creates appender /// </summary> /// <param name="appenderName">The class name of the appender. It should be in the provided namespace</param> /// <param name="layout">The layout in which the appender should append the given data</param> /// <param name="writableObject">The place where the appender will place the data</param> /// <returns></returns> public IAppender GetAppender(string appenderName, ILayout layout, IWritableObject writableObject) { var appenderType = Type.GetType(this.appendersNamespace.Length == 0 ? appenderName : $"{appendersNamespace}.{appenderName}"); var appender = Activator.CreateInstance(appenderType, layout, writableObject) as IAppender; return(appender); }
public void ToWriteFileAsync(IWritableObject writeable, string filePath) { string fullFilePath = Path.Combine(filePath, writeable.FileName); try { if (string.IsNullOrEmpty(fullFilePath)) { return; } if (!fullFilePath.Contains(".")) { return; } if (writeable.GetLines() == null) { return; } File.Create(fullFilePath).Close(); return; } catch (Exception e) { Console.WriteLine("Error: " + e); } Task task = new Task(delegate() { while (writeable.MoveNext()) { File.AppendText(filePath).WriteLine(writeable.Current); } }); task.Start(); }
public void WriteObject(string path, IWritableObject obj) { file = new FileInfo(Path.Combine(directory.FullName, path + ".txt")); file.CreateText().Close(); obj.Write(path, this); }
public ConsoleAppender(ILayout layout, IWritableObject console) : base(layout, console) { }
public void WriteObject(IWritableObject obj) { obj.Write(this); }
protected Appender(ILayout layout, IWritableObject writableObject) { this.layout = layout; this.writableObject = writableObject; }