/// <summary> /// Gets the Mongo database based on the connection string. IF the database name isn't /// present in the connection string it defaults to 'log4net'. /// </summary> /// <returns>The Mongo database</returns> protected virtual LiteDatabase CreateDatabaseConnection() { var fullPath = SystemInfo.ConvertToFullPath(this.File); var db = new LiteDatabase(fullPath); return(db); }
public override void ActivateOptions() { base.ActivateOptions(); new Thread(new ThreadStart(SearchBufferingFile2Send)).Start(); if (string.IsNullOrEmpty(m_LocalFileDirectory)) { LogLog.Error(declaringType, "m_LocalFileDirectory 变量配置为空,服务没法上传日志"); } else { m_LocalDirectorys = m_LocalFileDirectory.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < m_LocalDirectorys.Length; i++) { m_LocalDirectorys[i] = SystemInfo.ConvertToFullPath(m_LocalDirectorys[i]); } } if (m_BulkAppender != null) { if (typeof(ILogWrapper).IsAssignableFrom(m_BulkAppender.GetType())) { ((ILogWrapper)m_BulkAppender).Log = m_Log; } } }
/// <summary> /// Convert a path into a fully qualified path. /// </summary> /// <param name="path">The path to convert.</param> /// <returns>The fully qualified path.</returns> /// <remarks> /// <para> /// Converts the path specified to a fully /// qualified path. If the path is relative it is /// taken as relative from the application base /// directory. /// </para> /// </remarks> protected static string ConvertToFullPath(string path) { if (basePath != null) { path = Path.Combine(basePath, path); } return(SystemInfo.ConvertToFullPath(path)); }
/// <summary> /// 序列化到本地文件 /// </summary> /// <param name="events"></param> protected override void SendBuffer(LoggingData[] events) { string filename = SystemInfo.ConvertToFullPath(m_FileSaveDirectory + this.m_Name + "_" + DateTime.Now.ToString("yyyyMMddHHmmssffff") + ".temp"); SaveBuffer2File(filename, events); using (SecurityContext.Impersonate(this)) { File.Move(filename, filename.Replace(Path.GetExtension(filename), m_ExName)); } }
/// <summary> /// Gets the Mongo database based on the connection string. IF the database name isn't /// present in the connection string it defaults to 'log4net'. /// </summary> /// <returns>The Mongo database</returns> protected virtual LiteDatabase CreateDatabaseConnection() { if (IsStream) { return(new LiteDatabase(memoryStream)); } else { var fullPath = SystemInfo.ConvertToFullPath(this.File); liteFileInfo = new System.IO.FileInfo(fullPath); var db = new LiteDatabase(fullPath); return(db); } }
override protected void Append(LoggingEvent loggingEvent) { try { // Render the file name StringWriter stringWriter = new StringWriter(); m_filePattern.Format(stringWriter, loggingEvent); string fileName = stringWriter.ToString(); fileName = SystemInfo.ConvertToFullPath(fileName); FileStream fileStream = null; using (m_securityContext.Impersonate(this)) { // Ensure that the directory structure exists string directoryFullName = Path.GetDirectoryName(fileName); // Only create the directory if it does not exist // doing this check here resolves some permissions failures if (!Directory.Exists(directoryFullName)) { Directory.CreateDirectory(directoryFullName); } // Open file stream while impersonating fileStream = new FileStream(fileName, FileMode.Append, FileAccess.Write, FileShare.Read); } if (fileStream != null) { using (StreamWriter streamWriter = new StreamWriter(fileStream, m_encoding)) { RenderLoggingEvent(streamWriter, loggingEvent); } fileStream.Close(); } } catch (Exception ex) { ErrorHandler.Error("Failed to append to file", ex); } }
/// <summary> /// Convert a path into a fully qualified path. /// </summary> /// <param name="path">The path to convert.</param> /// <returns>The fully qualified path.</returns> /// <remarks> /// <para> /// Converts the path specified to a fully /// qualified path. If the path is relative it is /// taken as relative from the application base /// directory. /// </para> /// </remarks> protected static string ConvertToFullPath(string path) { return(SystemInfo.ConvertToFullPath(path)); }
protected static string ConvertToFullPath(string path) => SystemInfo.ConvertToFullPath(path);