Example #1
0
        public Task LogAsync(LogMessage msg)
        {
            // Variables declaration
            string message = msg.Exception?.ToString() ?? msg.Message;

            // Use different loggers for different severity levels
            switch (msg.Severity)
            {
            case LogSeverity.Critical:
                _logger.LogCritical(message);
                break;

            case LogSeverity.Error:
                _logger.LogError(message);
                break;

            case LogSeverity.Warning:
                _logger.LogWarning(message);
                break;

            case LogSeverity.Info:
                _logger.LogInformation(message);
                break;

            case LogSeverity.Debug:
                _logger.LogDebug(message);
                break;

            default:
                _logger.LogDefault(message);
                break;
            }

            // Log to filesystem.
            // W.I.P

            // Once all tasks have been completed, return 'Task.CompletedTask'
            return(Task.CompletedTask);
        }
Example #2
0
        public async Task CommandExecutedAsync(Optional <CommandInfo> command, ICommandContext context, IResult result)
        {
            // Variables declaration
            int i;

            // command is unspecified when there was a search failure (command not found); we don't care about these errors
            if (!command.IsSpecified)
            {
                return;
            }

            // If the command failed, let's notify the user that something happened and log the result to the console.
            if (!result.IsSuccess)
            {
                _logger.LogWarning($"Command failed with result: {result}");
                await context.Channel.SendMessageAsync($"Error: {result}");
            }

            // Update user's 'stackCooldown' entry (I know for sure user exists in 'stackCooldown' because of the check on 'MessageReceivedAsync')
            i = Client.stackCooldown.userStack.IndexOf((SocketUser)context.User); // Get user index on 'userStack' (used to get correct timestamp for user's last command execution).
            Client.stackCooldown.lastCommandAt[i] = DateTime.Now;                 // If user is not on cooldown, update user's last command execution timestamp.
        }
Example #3
0
    private void createList()
    {
        CustomLogger.LogInformation("fizzbuzzmodel: generating list, max: " + max);

        if (max <= 0)
        {
            CustomLogger.LogWarning("fizzbuzzmodel: max value must be strictly positive, changing value to 20");
            max = 20;
        }

        string[] list = new string[max + 1];

        for (int i = 1; i <= max; i++)
        {
            if (i % 3 == 0 && i % 5 == 0)
            {
                list[i] = "fizzbuzz";
            }
            else if (i % 3 == 0)
            {
                list[i] = "fizz";
            }
            else if (i % 5 == 0)
            {
                list[i] = "buzz";
            }
            else
            {
                list[i] = i.ToString();
            }
        }

        fizzBuzzList = list;

        CustomLogger.LogInformation("fizzbuzzmodel: list generated");
    }