Centreon_EventLog_2_Syslog.Debug.Write C# (CSharp) Method

Write() public method

Write error into log file
public Write ( String processName, String line, System.DateTime dtError, int errorLevel ) : System.Boolean
processName String Name of the process which wants to write error
line String Error to write
dtError System.DateTime DateTime when of error
errorLevel int
return System.Boolean
        public Boolean Write(String processName, String line, DateTime dtError, int errorLevel)
        {
            // Write debug if debug is active and level is correct
            if ((this._DebugInfo.Level != 0) && (errorLevel <= this._DebugInfo.Versobe))
            {
                StreamWriter stw;

                if (dtError == null)
                {
                    dtError = DateTime.Now;
                }

                try
                {
                    long debugFileSize = 0;
                    if (File.Exists(this._FileName))
                    {
                        FileInfo f = new FileInfo(this._FileName);
                        debugFileSize = f.Length;
                    }

                    lock (this)
                    {
                        if (debugFileSize > (this._DebugInfo.MaxSize * 1024 * 1024))
                        {
                            rotateFile();
                        }
                        stw = new StreamWriter(File.Open(this._FileName, FileMode.Append));
                        stw.WriteLine(String.Format("[{0}.{1}] {2} :: {3}", dtError, dtError.Millisecond, processName, line));
                        stw.Close();
                    }
                }
                catch (System.ObjectDisposedException ode)
                {
                    Console.WriteLine(ode.Message);
                }
                catch (System.IO.IOException ioe)
                {
                    Console.WriteLine(ioe.Message);
                }
                catch (System.Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }

            return true;
        }