Skip to content

Try-Catch-Finally handler #9

Description

@catalingavan

Create a try-catch-finally handler which will automatically log when a method starts and when it completes.

Usage

public async Task DeleteAsync()
{
    ILogger logger = Logger.Factory.Get();;

    await logger.TryCatchFinallyAsync("DeleteAlerts", async () =>
    {
        await DeleteAlertsAsync();
    });

    await logger.TryCatchFinallyAsync("DeleteRequestLogs", async () =>
    {
        await DeleteRequestLogsAsync();
    });
}

Output

[DEBUG] DeleteAlerts > start

@........ DeleteAlertsAsync() executing

[DEBUG] DeleteAlerts > complete



[DEBUG] DeleteRequestLogs > start

@........ DeleteRequestLogsAsync() executing

[ERROR] System.NullReferenceException: Object reference not set to an instance of an object.
[DEBUG] DeleteRequestLogs > complete

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions