Exemplo n.º 1
0
        static void Main()
        {
            var test = Result.SingleTrace("Test trace.");

            test += Result.SingleDebug("Test debug.");
            test += Result.SingleInfo("Test info.");
            test += Result.SingleWarning("Test warning.");
            test += Result.SingleError("Test error.");
            test += Result.SingleFatal("Test fatal.");

            Logger.LogSynchronous(test);
            Logger.Remove("ConsoleLogger");

            var inline        = Result.SingleInfo("Woah.");
            var inlineMessage = Writer.Message;

            inlineMessage.AppendFormat(OmniColours.BrightWhite, "{0,-15}", "This")
            .Append("is a ").Append(OmniColours.BrightCyan, "message").Append(" for the masses.");

            inline += LoggingResult.SingleInfo(inlineMessage);
            inline += Result.SingleWarning("There it was.");
            inline += Result.SingleInfo("And there it went.");

            inline += LoggingResult.SingleInfo("And a single logging message.");

            Logger.LogSynchronous(inline);
        }
Exemplo n.º 2
0
        public async Task <ActionResult <LoggingResult> > GetAsync(DateTimeOffset minTimestamp, DateTimeOffset maxTimestamp, int maxEntries, string searchString)
        {
            var result = new LoggingResult();

            // Build logging request
            var request = new LoggingRequest()
            {
                MinTimeStamp    = minTimestamp.UtcDateTime,
                MaxTimeStamp    = maxTimestamp.UtcDateTime,
                MaxCountEntries = maxEntries,
                SearchString    = searchString
            };

            // Validate
            try
            {
                Validator.ValidateObject(request, new ValidationContext(request), true);
            }
            catch (ValidationException ex)
            {
                return(BadRequest(ex.Message));
            }

            // Simulate some working time
            await Task.Delay(1000);

            // Generate entries
            var messageBuilder    = new StringBuilder(128);
            var entriesToGenerate = maxEntries < 100 ? maxEntries : 100;
            var actTimeStamp      = request.MaxTimeStamp;

            for (var loop = 0; loop < entriesToGenerate; loop++)
            {
                if (actTimeStamp < request.MinTimeStamp)
                {
                    break;
                }

                messageBuilder.Clear();
                messageBuilder.Append("This is a generated message");
                if (!string.IsNullOrEmpty(searchString))
                {
                    messageBuilder.Append(" (");
                    messageBuilder.Append(searchString);
                    messageBuilder.Append(")");
                }

                result.Lines.Add(new LoggingLine()
                {
                    TimeStamp = actTimeStamp,
                    Category  = "Test",
                    Message   = messageBuilder.ToString()
                });

                actTimeStamp = actTimeStamp - TimeSpan.FromMinutes(1.0);
            }

            return(result);
        }
Exemplo n.º 3
0
        public async Task <LoggingResult> GetLoggingAsync(LoggingRequest request)
        {
            var result = new LoggingResult();

            // Simulate some working time
            await Task.Delay(1000);

            // Generate entries
            var messageBuilder    = new StringBuilder(128);
            var entriesToGenerate = request.MaxCountEntries < 100 ? request.MaxCountEntries : 100;
            var actTimeStamp      = request.MaxTimeStamp;

            for (var loop = 0; loop < entriesToGenerate; loop++)
            {
                if (actTimeStamp < request.MinTimeStamp)
                {
                    break;
                }

                messageBuilder.Clear();
                messageBuilder.Append("This is a generated message");
                if (!string.IsNullOrEmpty(request.SearchString))
                {
                    messageBuilder.Append(" (");
                    messageBuilder.Append(request.SearchString);
                    messageBuilder.Append(")");
                }

                result.Lines.Add(new LoggingLine()
                {
                    TimeStamp = actTimeStamp,
                    Category  = "Test",
                    Message   = messageBuilder.ToString()
                });

                actTimeStamp = actTimeStamp - TimeSpan.FromMinutes(1.0);
            }

            return(result);
        }
Exemplo n.º 4
0
 public void Log(LoggingResult result)
 {
     File.WriteAllText(@"c:\tmp\log.txt", DateTime.Now.ToString());
 }
Exemplo n.º 5
0
 protected override Result LogIssues(ResultIssue[] issues)
 {
     return(Loggers.Aggregate(Result.Success, (r, l) => r + l.LogSynchronous(LoggingResult.FromIssues(issues))));
 }