public override void Close() { started = false; while (finished == false) { if (sleeping == true) { started = false; logEvent.Set(); } Thread.Sleep(100); } if (InsertCmd != null) { InsertCmd.Dispose(); InsertCmd = null; } if (Sql != null) { Sql.Close(); Sql = null; } if (FileWriter != null) { FileWriter.Close(); FileWriter = null; } Th = null; initialized = false; }
protected override void Init() { initialized = false; if (FileWriter == null) { FileWriter = new FileWriter(workingFolder); } try { Sql = new SQL(SQLClientType.MSSQL); Sql.ConnectionString = connectionString; //Check database for errors and recreate Db if get reoubles with connection if (Sql.DbObjectExist(enmDbObjectType.Table, loggingTableName) == false) { CreateLogTable(Sql, loggingTableName, Log.StaticDataColumns); } Action <SqlException> vCurrentErrorHandler = Sql.ErrorHandler; Sql.ErrorHandler = null; try { string vStrSqlSelect = string.Format("SELECT COUNT(*) FROM [{0}] ;", loggingTableName); Sql.Value(vStrSqlSelect); } catch { Sql.Connection.Close(); Sql.ConnectionString = connectionString; CreateLogTable(Sql, loggingTableName, Log.StaticDataColumns); } finally { Sql.ErrorHandler = vCurrentErrorHandler; } if (InsertCmd != null) { InsertCmd.Dispose(); InsertCmd = null; } InsertCmd = GetInsertCommand(Sql, Log.StaticDataColumns); if (queue == null) { queue = new List <LogData>(); } if (logEvent == null) { logEvent = new ManualResetEvent(false); } if (Th == null) { Th = new Thread(new ThreadStart(this.Writer)); Th.Name = this.GetType().FullName + ".Writer"; Th.Start(); } initialized = true; } catch (Exception Ex) { FileWriter.Write(new SysLogData(this.GetType().FullName, "New", Ex)); initialized = false; } }