コード例 #1
0
        public static void LogMessage(string message, EnumNivelLog messageType, bool withTimeStamp)
        {
            if (withTimeStamp)
            {
                message = DateTime.Now.ToString("dd/MM/yy-H:mm:ss: ") + message;
            }

            LogManager.Configuration.Reload();

            // Logueo solo si el nivel de log del mensaje es mayor o igual al configurado
            if (messageType >= LEVEL_LOG)
            {
                switch (LEVEL_LOG)
                {
                case EnumNivelLog.Trace: lo.Trace(message, logM); break;

                case EnumNivelLog.Debug: lo.Debug(message, logM); break;

                case EnumNivelLog.Info: lo.Info(message, logM); break;

                case EnumNivelLog.Warn: lo.Warn(message, logM); break;

                case EnumNivelLog.Error: lo.Error(message, logM); break;

                case EnumNivelLog.Fatal: lo.Fatal(message, logM); break;
                }
            }
        }
コード例 #2
0
ファイル: Comunicacion.cs プロジェクト: gabalesev/modulocom
        public Comunicacion(BaseConfig baseConf, ArchivoConfig conf)
        {
            TransacManager.ProtoConfig = new ProtocoloConfig(baseConf, conf);

            switch (TransacManager.ProtoConfig.CONFIG.LevelLog)
            {
                case EnumMessageType.DEBUG: NivelLog = EnumNivelLog.Trace; break;
                case EnumMessageType.ERROR: NivelLog = EnumNivelLog.Error; break;
                case EnumMessageType.NORMAL: NivelLog = EnumNivelLog.Info; break;
                case EnumMessageType.NOTHING: NivelLog = EnumNivelLog.Off; break;
                case EnumMessageType.WARNING: NivelLog = EnumNivelLog.Warn; break;
            }

            DateTime d = DateTime.Now;

            string fName = conf.LogFileName.Split('.')[0]
                + d.Year.ToString().PadLeft(2, '0')
                + d.Month.ToString().PadLeft(2, '0')
                + d.Day.ToString().PadLeft(2, '0')
                + d.Hour.ToString().PadLeft(2, '0')
                + d.Minute.ToString().PadLeft(2, '0')
                + d.Second.ToString().PadLeft(2, '0')
                + "." + conf.LogFileName.Split('.')[1];

            LogBMTP.InicializaLog(conf, NivelLog, fName);

            TR = new TransacManager();
        }
コード例 #3
0
ファイル: LogBMTP.cs プロジェクト: gabalesev/modulocom
        public static void InicializaLog(ArchivoConfig lee, EnumNivelLog lvlLog, string fileName, string tipo = "")
        {
            try
            {
                BASE_DIR = lee.LogPath;
                MAX_SIZE_FILE = lee.LogMaxFileSize;
                NUMERING_WITH_SEQUENTIAL = lee.NumeringWithSecuential;
                LEVEL_LOG = lvlLog; //(LogLevel)lee.LevelLog;
                FILE_NAME = fileName;
            }
            catch
            {
            }

            if (!Directory.Exists(BASE_DIR))
            {
                Directory.CreateDirectory(BASE_DIR);
            }

            LoggingConfiguration confLog = new LoggingConfiguration();

            console = new ColoredConsoleTarget { 
                Name = "console",
                Layout = "${shortdate} ${level} ${message}"
            };

            fileTargetM = new FileTarget
            {
                FileName = BASE_DIR + FILE_NAME,
                Layout = "${message}",
                ArchiveAboveSize = MAX_SIZE_FILE,                
                ArchiveNumbering = ArchiveNumberingMode.Sequence
            };

            LogLevel lv = LogLevel.Off;
            switch(LEVEL_LOG)
            {
                case EnumNivelLog.Trace: lv = LogLevel.Trace; break;
                case EnumNivelLog.Debug: lv = LogLevel.Debug; break;
                case EnumNivelLog.Info: lv = LogLevel.Info; break;
                case EnumNivelLog.Error: lv = LogLevel.Error; break;
                case EnumNivelLog.Warn: lv = LogLevel.Warn; break;
                case EnumNivelLog.Fatal: lv = LogLevel.Fatal; break;
            }
            
            logRuleConsole = new NLog.Config.LoggingRule("*", lv, console);
            logRuleFileM = new NLog.Config.LoggingRule("*", lv, fileTargetM);

            confLog.AddTarget("console", console);
            confLog.AddTarget("fileM", fileTargetM);
            confLog.LoggingRules.Add(logRuleConsole);
            confLog.LoggingRules.Add(logRuleFileM);
#if DEBUG
            LogManager.ThrowExceptions = true;
#endif
            LogManager.Configuration = confLog;
            
            logM += new LogMessageGenerator(LogMensaje);
        }
コード例 #4
0
        public static void InicializaLog(ArchivoConfig lee, EnumNivelLog lvlLog, string fileName, string tipo = "")
        {
            try
            {
                BASE_DIR                 = lee.LogPath;
                MAX_SIZE_FILE            = lee.LogMaxFileSize;
                NUMERING_WITH_SEQUENTIAL = lee.NumeringWithSecuential;
                LEVEL_LOG                = lvlLog; //(LogLevel)lee.LevelLog;
                FILE_NAME                = fileName;
            }
            catch
            {
            }

            if (!Directory.Exists(BASE_DIR))
            {
                Directory.CreateDirectory(BASE_DIR);
            }

            LoggingConfiguration confLog = new LoggingConfiguration();

            console = new ColoredConsoleTarget
            {
                Name   = "console",
                Layout = "${shortdate} ${level} ${message}"
            };

            fileTargetM = new FileTarget
            {
                FileName         = BASE_DIR + FILE_NAME,
                Layout           = "${message}",
                ArchiveAboveSize = MAX_SIZE_FILE,
                ArchiveNumbering = ArchiveNumberingMode.Sequence
            };

            LogLevel lv = LogLevel.Off;

            switch (LEVEL_LOG)
            {
            case EnumNivelLog.Trace: lv = LogLevel.Trace; break;

            case EnumNivelLog.Debug: lv = LogLevel.Debug; break;

            case EnumNivelLog.Info: lv = LogLevel.Info; break;

            case EnumNivelLog.Error: lv = LogLevel.Error; break;

            case EnumNivelLog.Warn: lv = LogLevel.Warn; break;

            case EnumNivelLog.Fatal: lv = LogLevel.Fatal; break;
            }

            logRuleConsole = new LoggingRule("*", lv, console);
            logRuleFileM   = new LoggingRule("*", lv, fileTargetM);

            confLog.AddTarget("console", console);
            confLog.AddTarget("fileM", fileTargetM);
            confLog.LoggingRules.Add(logRuleConsole);
            confLog.LoggingRules.Add(logRuleFileM);
#if DEBUG
            LogManager.ThrowExceptions = true;
#endif
            LogManager.Configuration = confLog;

            logM += new LogMessageGenerator(LogMensaje);
        }
コード例 #5
0
        public static void LogBuffer(char[] buffer, string title, int lenghtUsedBuffer, EnumNivelLog nivelLog, int numberBase = 16)
        {
            if (LEVEL_LOG.Equals(EnumMessageType.NOTHING))
            {
                // Esta configurado para no loguear nada
                return;
            }

            if (lenghtUsedBuffer > buffer.Length)
            {
                //ERROR: Base de numeracion no valida.
                LogMessage(string.Format("dump:Cantidad de buffer usado({0}) mayor que el tamaño del buffer({1}).\n", lenghtUsedBuffer, buffer.Length), EnumNivelLog.Error, false);
                return;
            }
            StringBuilder sb = new StringBuilder();

            //Logueo Title
            sb.AppendLine(title);

            string lineaDoble        = string.Empty;
            string logRegistryNumber = string.Empty;
            string logEmptyChar      = string.Empty;
            string loguerChar        = "   ";
            string loguerCharNo16    = "    ";
            char   oneItemBuffer     = ' ';

            char[] numberToHexa = new char[16] {
                '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'
            };

            switch (numberBase)
            {
            case 16:
                //Logueo HEADER_16
                sb.AppendLine(HEADER_16);

                //Logueo linea doble
                sb.AppendLine(lineaDoble.PadLeft(HEADER_16.Length, HEADER_LINE));
                break;

            case 10:
                //Logueo HEADER_10
                sb.AppendLine(HEADER_10);

                //Logueo linea doble
                sb.AppendLine(lineaDoble.PadLeft(HEADER_10.Length, HEADER_LINE));
                break;

            /*case 8:
             *  //Logueo HEADER_08
             *  sb.AppendLine(HEADER_08);
             *
             *  //Logueo linea doble
             *  sb.AppendLine(lineaDoble.PadLeft(HEADER_08.Length, HEADER_LINE));
             *  break;*/
            default:
                //ERROR: Base de numeracion no valida.
                LogMessage(string.Format("dump:base={0} inválida.\n", numberBase), EnumNivelLog.Error, false);
                return;
            }
            //Calculo cantidad de lineas que voy a tener que loguear
            int countLines;

            if (lenghtUsedBuffer % numberBase == 0)
            {
                countLines = lenghtUsedBuffer / numberBase;
            }
            else
            {
                countLines = (lenghtUsedBuffer / numberBase) + 1;
            }

            //Itero en la cantidad de lineas
            for (int i = 0; i < countLines; i++)
            {
                string oneLine = string.Empty;

                //Logueo numero de registro:
                switch (numberBase)
                {
                case 16:
                    oneLine += intToHexa(i).PadLeft(7, '0') + "0 | ";
                    break;

                case 10:
                    oneLine += i.ToString().PadLeft(7, '0') + "0 | ";
                    break;

                    /*case 8:
                     *  oneLine += intToOct(i).PadLeft(7, '0') + "0 | ";
                     *  break;*/
                }
                //Itero dentro de una linea en cada valor a loguear
                for (int j = 0; j < numberBase; j++)
                {
                    if (i * numberBase + j >= lenghtUsedBuffer)
                    {
                        if (numberBase == 16)
                        {
                            oneLine += loguerChar;
                        }
                        else
                        {
                            oneLine += loguerCharNo16;
                        }
                    }
                    else
                    {
                        oneItemBuffer = buffer[i * numberBase + j];
                        switch (numberBase)
                        {
                        case 16:
                            oneLine += numberToHexa[oneItemBuffer >> 4].ToString() + numberToHexa[oneItemBuffer & 0xf].ToString() + " ";
                            break;

                        case 10:
                            oneLine += string.Format("{0} ", Convert.ToByte(oneItemBuffer).ToString().PadLeft(3, '0'));
                            break;

                            /*case 8:
                             *  oneLine += string.Format("{0} ", Convert.ToByte(oneItemBuffer).ToString().PadLeft(3, '0'));
                             *  break;*/
                        }
                    }
                }
                oneLine += "| ";
                //Itero dentro de una linea en cada valor a loguear como Ascii
                for (int j = 0; j < numberBase; j++)
                {
                    if (i * numberBase + j < lenghtUsedBuffer)
                    {
                        oneItemBuffer = buffer[i * numberBase + j];
                        if (oneItemBuffer > 0x1f && oneItemBuffer < 0x7f)
                        {
                            oneLine += oneItemBuffer;
                        }
                        else
                        {
                            oneLine += '.';
                        }
                    }
                    else
                    {
                        oneLine += " ";
                    }
                }
                sb.AppendLine(oneLine);
            }

            LogMessage(sb.ToString(), nivelLog, true);
        }
コード例 #6
0
ファイル: LogBMTP.cs プロジェクト: gabalesev/modulocom
        public static void LogBuffer(char[] buffer, string title, int lenghtUsedBuffer, EnumNivelLog nivelLog, int numberBase = 16)
        {
            if (LEVEL_LOG.Equals(EnumMessageType.NOTHING))
            {
                // Esta configurado para no loguear nada
                return;
            }

            if (lenghtUsedBuffer > buffer.Length)
            {
                //ERROR: Base de numeracion no valida.
                LogMessage(string.Format("dump:Cantidad de buffer usado({0}) mayor que el tamaño del buffer({1}).\n", lenghtUsedBuffer, buffer.Length), EnumNivelLog.Error, false );
                return;
            }
            StringBuilder sb = new StringBuilder();
            //Logueo Title
            sb.AppendLine(title);

            string lineaDoble = string.Empty;
            string logRegistryNumber = string.Empty;
            string logEmptyChar = string.Empty;
            string loguerChar = "   ";
            string loguerCharNo16 = "    ";
            char oneItemBuffer = ' ';
            char[] numberToHexa = new char[16] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };

            switch (numberBase)
            {
                case 16:
                    //Logueo HEADER_16
                    sb.AppendLine(HEADER_16);

                    //Logueo linea doble
                    sb.AppendLine(lineaDoble.PadLeft(HEADER_16.Length, HEADER_LINE));
                    break;
                case 10:
                    //Logueo HEADER_10
                    sb.AppendLine(HEADER_10);

                    //Logueo linea doble
                    sb.AppendLine(lineaDoble.PadLeft(HEADER_10.Length, HEADER_LINE));
                    break;
                /*case 8:
                    //Logueo HEADER_08
                    sb.AppendLine(HEADER_08);

                    //Logueo linea doble
                    sb.AppendLine(lineaDoble.PadLeft(HEADER_08.Length, HEADER_LINE));
                    break;*/
                default:
                    //ERROR: Base de numeracion no valida.
                    LogMessage(string.Format("dump:base={0} inválida.\n", numberBase), EnumNivelLog.Error, false);
                    return;
            }
            //Calculo cantidad de lineas que voy a tener que loguear
            int countLines;
            if (lenghtUsedBuffer % numberBase == 0)
            {
                countLines = lenghtUsedBuffer / numberBase;
            }
            else
            {
                countLines = (lenghtUsedBuffer / numberBase) + 1;
            }

            //Itero en la cantidad de lineas
            for (int i = 0; i < countLines; i++)
            {
                string oneLine = string.Empty;

                //Logueo numero de registro: 
                switch (numberBase)
                {
                    case 16:
                        oneLine += intToHexa(i).PadLeft(7, '0') + "0 | ";
                        break;
                    case 10:
                        oneLine += i.ToString().PadLeft(7, '0') + "0 | ";
                        break;
                    /*case 8:
                        oneLine += intToOct(i).PadLeft(7, '0') + "0 | ";
                        break;*/
                }
                //Itero dentro de una linea en cada valor a loguear
                for (int j = 0; j < numberBase; j++)
                {
                    if (i * numberBase + j >= lenghtUsedBuffer)
                    {
                        if (numberBase == 16)
                        {
                            oneLine += loguerChar;
                        }
                        else
                        {
                            oneLine += loguerCharNo16;
                        }
                    }
                    else
                    {
                        oneItemBuffer = buffer[i * numberBase + j];
                        switch (numberBase)
                        {
                            case 16:
                                oneLine += numberToHexa[oneItemBuffer >> 4].ToString() + numberToHexa[oneItemBuffer & 0xf].ToString() + " ";
                                break;
                            case 10:
                                oneLine += string.Format("{0} ", Convert.ToByte(oneItemBuffer).ToString().PadLeft(3, '0'));
                                break;
                            /*case 8:
                                oneLine += string.Format("{0} ", Convert.ToByte(oneItemBuffer).ToString().PadLeft(3, '0'));
                                break;*/
                        }
                    }
                }
                oneLine += "| ";
                //Itero dentro de una linea en cada valor a loguear como Ascii
                for (int j = 0; j < numberBase; j++)
                {
                    if (i * numberBase + j < lenghtUsedBuffer)
                    {
                        oneItemBuffer = buffer[i * numberBase + j];
                        if (oneItemBuffer > 0x1f && oneItemBuffer < 0x7f)
                        {
                            oneLine += oneItemBuffer;
                        }
                        else
                        {
                            oneLine += '.';
                        }
                    }
                    else
                    {
                        oneLine += " ";
                    }
                }
                sb.AppendLine(oneLine);
            }

            LogMessage(sb.ToString(), nivelLog, true);
        }
コード例 #7
0
ファイル: LogBMTP.cs プロジェクト: gabalesev/modulocom
        public static void LogMessage(string message, EnumNivelLog messageType, bool withTimeStamp)
        {
            if (withTimeStamp)
            {
                message = DateTime.Now.ToString("dd/MM/yy-H:mm:ss: ") + message;
            }

            LogManager.Configuration.Reload();

            // Logueo solo si el nivel de log del mensaje es mayor o igual al configurado
            if (messageType >= LEVEL_LOG)
            {
                switch (LEVEL_LOG)
                {
                    case EnumNivelLog.Trace: lo.Trace(message, logM); break;
                    case EnumNivelLog.Debug: lo.Debug(message, logM); break;
                    case EnumNivelLog.Info: lo.Info(message, logM); break;
                    case EnumNivelLog.Warn: lo.Warn(message, logM); break;
                    case EnumNivelLog.Error: lo.Error(message, logM); break;
                    case EnumNivelLog.Fatal: lo.Fatal(message, logM); break;

                }              
            }
        }