Exemplo n.º 1
0
        public bool LogToTraceLog(string logEntry, TraceLogLevels level)
        {
            try
            {
                System.DateTime dt         = DateTime.Now;
                string          dateString = dt.ToString("MM-dd-yyyy hh:mm:ss");
                string          outString;

                string traceLevel;
                switch (level)
                {
                case TraceLogLevels.ServiceLevel:
                    traceLevel = "SERVICE";
                    break;

                case TraceLogLevels.InitialReadLevel:
                    traceLevel = "FILE READ";
                    break;

                case TraceLogLevels.FileParseLevel:
                    traceLevel = "PARSE";
                    break;

                case TraceLogLevels.FileWriteLevel:
                    traceLevel = "FILE WRITE";
                    break;

                case TraceLogLevels.FilePrintLevel:
                    traceLevel = "FILE PRINT";
                    break;

                case TraceLogLevels.ConfigurationDump:
                    traceLevel = "CONFIGURATION";
                    break;

                default:
                    traceLevel = "";
                    break;
                }
                outString = string.Format("{0} {1}: {2}\r\n", dateString, traceLevel, logEntry);
                if (outString.Length > 0)
                {
                    byte[] info = new UTF8Encoding(true).GetBytes(outString);
                    traceFileStream.Write(info, 0, info.Length);
                    traceFileStream.Flush();
                }
                return(true);
            }
            catch (Exception ex)
            {
                if (ErrorLogInitialized)
                {
                    LogError("Error in LogToTraceLog().  Error: " + ex.Message, EventLogEntryType.Error, false);
                }
                return(false);
            }
        }
Exemplo n.º 2
0
        public bool LogToTraceLog(string logEntry, TraceLogLevels level)
        {
            try
            {
                System.DateTime dt         = DateTime.Now;
                string          dateString = dt.ToString("MMddyyyy hhmmss");
                string          outString;
                switch (level)
                {
                case TraceLogLevels.ServiceLevel:
                    outString = dateString + " SERVICE: " + logEntry;
                    break;

                case TraceLogLevels.InitialReadLevel:
                    outString = dateString + " FILE READ: " + logEntry;
                    break;

                case TraceLogLevels.FileParseLevel:
                    outString = dateString + " PARSE: " + logEntry;
                    break;

                case TraceLogLevels.FileWriteLevel:
                    outString = dateString + " FILE WRITE: " + logEntry;
                    break;

                case TraceLogLevels.FilePrintLevel:
                    outString = dateString + " FILE PRINT: " + logEntry;
                    break;

                case TraceLogLevels.ConfigurationDump:
                    outString = dateString + " CONFIGURATION: " + logEntry;
                    break;

                default:
                    outString = dateString + " " + logEntry;
                    break;
                }
                if (outString.Length > 0)
                {
                    byte[] info = new UTF8Encoding(true).GetBytes(outString);
                    traceFileStream.Write(info, 0, info.Length);
                    traceFileStream.Flush();
                }
                return(true);
            }
            catch (Exception ex)
            {
                if (ErrorLogInitialized)
                {
                    LogError("Error in LogToTraceLog().  Error: " + ex.Message, EventLogEntryType.Error, false);
                }
                return(false);
            }
        }