Exemplo n.º 1
0
        public long Log(ServiceCtx Context)
        {
            (long BufPos, long BufSize) = Context.Request.GetBufferType0x21();
            byte[] LogBuffer = Context.Memory.ReadBytes(BufPos, BufSize);

            using (MemoryStream MS = new MemoryStream(LogBuffer))
            {
                BinaryReader Reader = new BinaryReader(MS);

                long  Pid           = Reader.ReadInt64();
                long  ThreadContext = Reader.ReadInt64();
                short Flags         = Reader.ReadInt16();
                byte  Level         = Reader.ReadByte();
                byte  Verbosity     = Reader.ReadByte();
                int   PayloadLength = Reader.ReadInt32();

                StringBuilder SB = new StringBuilder();

                SB.AppendLine("Guest log:");

                while (MS.Position < MS.Length)
                {
                    byte Type = Reader.ReadByte();
                    byte Size = Reader.ReadByte();

                    LmLogField Field = (LmLogField)Type;

                    string FieldStr = string.Empty;

                    if (Field == LmLogField.Start)
                    {
                        Reader.ReadBytes(Size);

                        continue;
                    }
                    else if (Field == LmLogField.Stop)
                    {
                        break;
                    }
                    else if (Field == LmLogField.Line)
                    {
                        FieldStr = Field + ": " + Reader.ReadInt32();
                    }
                    else if (Field == LmLogField.DropCount)
                    {
                        FieldStr = Field + ": " + Reader.ReadInt64();
                    }
                    else if (Field == LmLogField.Time)
                    {
                        FieldStr = Field + ": " + Reader.ReadInt64() + "s";
                    }
                    else if (Field < LmLogField.Count)
                    {
                        FieldStr = Field + ": \"" + Encoding.UTF8.GetString(Reader.ReadBytes(Size)) + "\"";
                    }
                    else
                    {
                        FieldStr = "Field" + Field + ": \"" + Encoding.UTF8.GetString(Reader.ReadBytes(Size)) + "\"";
                    }

                    SB.AppendLine(" " + FieldStr);
                }

                string Text = SB.ToString();

                switch ((LmLogLevel)Level)
                {
                case LmLogLevel.Trace:    Context.Device.Log.PrintDebug(LogClass.ServiceLm, Text); break;

                case LmLogLevel.Info:     Context.Device.Log.PrintInfo(LogClass.ServiceLm, Text); break;

                case LmLogLevel.Warning:  Context.Device.Log.PrintWarning(LogClass.ServiceLm, Text); break;

                case LmLogLevel.Error:    Context.Device.Log.PrintError(LogClass.ServiceLm, Text); break;

                case LmLogLevel.Critical: Context.Device.Log.PrintError(LogClass.ServiceLm, Text); break;
                }
            }

            return(0);
        }
Exemplo n.º 2
0
        public long Log(ServiceCtx context)
        {
            (long bufPos, long bufSize) = context.Request.GetBufferType0x21();
            byte[] logBuffer = context.Memory.ReadBytes(bufPos, bufSize);

            using (MemoryStream ms = new MemoryStream(logBuffer))
            {
                BinaryReader reader = new BinaryReader(ms);

                long  pid           = reader.ReadInt64();
                long  threadContext = reader.ReadInt64();
                short flags         = reader.ReadInt16();
                byte  level         = reader.ReadByte();
                byte  verbosity     = reader.ReadByte();
                int   payloadLength = reader.ReadInt32();

                StringBuilder sb = new StringBuilder();

                sb.AppendLine("Guest log:");

                sb.AppendLine($" Log level: {(LmLogLevel)level}");

                while (ms.Position < ms.Length)
                {
                    byte type = reader.ReadByte();
                    byte size = reader.ReadByte();

                    LmLogField field = (LmLogField)type;

                    string fieldStr = string.Empty;

                    if (field == LmLogField.Start)
                    {
                        reader.ReadBytes(size);

                        continue;
                    }
                    else if (field == LmLogField.Stop)
                    {
                        break;
                    }
                    else if (field == LmLogField.Line)
                    {
                        fieldStr = $"{field}: {reader.ReadInt32()}";
                    }
                    else if (field == LmLogField.DropCount)
                    {
                        fieldStr = $"{field}: {reader.ReadInt64()}";
                    }
                    else if (field == LmLogField.Time)
                    {
                        fieldStr = $"{field}: {reader.ReadInt64()}s";
                    }
                    else if (field < LmLogField.Count)
                    {
                        fieldStr = $"{field}: '{Encoding.UTF8.GetString(reader.ReadBytes(size)).TrimEnd()}'";
                    }
                    else
                    {
                        fieldStr = $"Field{field}: '{Encoding.UTF8.GetString(reader.ReadBytes(size)).TrimEnd()}'";
                    }

                    sb.AppendLine(" " + fieldStr);
                }

                string text = sb.ToString();

                Logger.PrintGuest(LogClass.ServiceLm, text);
            }

            return(0);
        }
Exemplo n.º 3
0
        private string LogImpl(ServiceCtx context)
        {
            (long bufPos, long bufSize) = context.Request.GetBufferType0x21();

            byte[] logBuffer = new byte[bufSize];

            context.Memory.Read((ulong)bufPos, logBuffer);

            using MemoryStream ms = new MemoryStream(logBuffer);

            BinaryReader reader = new BinaryReader(ms);

            long  pid           = reader.ReadInt64();
            long  threadContext = reader.ReadInt64();
            short flags         = reader.ReadInt16();
            byte  level         = reader.ReadByte();
            byte  verbosity     = reader.ReadByte();
            int   payloadLength = reader.ReadInt32();

            StringBuilder sb = new StringBuilder();

            sb.AppendLine($"Guest Log:\n  Log level: {(LmLogLevel)level}");

            while (ms.Position < ms.Length)
            {
                int type = ReadEncodedInt(reader);
                int size = ReadEncodedInt(reader);

                LmLogField field = (LmLogField)type;

                string fieldStr = string.Empty;

                if (field == LmLogField.Start)
                {
                    reader.ReadBytes(size);

                    continue;
                }
                else if (field == LmLogField.Stop)
                {
                    break;
                }
                else if (field == LmLogField.Line)
                {
                    fieldStr = $"{field}: {reader.ReadInt32()}";
                }
                else if (field == LmLogField.DropCount)
                {
                    fieldStr = $"{field}: {reader.ReadInt64()}";
                }
                else if (field == LmLogField.Time)
                {
                    fieldStr = $"{field}: {reader.ReadInt64()}s";
                }
                else if (field < LmLogField.Count)
                {
                    fieldStr = $"{field}: '{Encoding.UTF8.GetString(reader.ReadBytes(size)).TrimEnd()}'";
                }
                else
                {
                    fieldStr = $"Field{field}: '{Encoding.UTF8.GetString(reader.ReadBytes(size)).TrimEnd()}'";
                }

                sb.AppendLine($"    {fieldStr}");
            }

            return(sb.ToString());
        }