Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to profile a class library #676

Open
AlbertoVPersonal opened this issue Oct 21, 2024 · 0 comments
Open

How to profile a class library #676

AlbertoVPersonal opened this issue Oct 21, 2024 · 0 comments

Comments

@AlbertoVPersonal
Copy link

Current version MiniProfiler

4.3.8

Current version .NET

.NET Core 8.0.4

Expected behaviour

I would like to profile a class library internally.

My class is similar to:

public class StateManagement() : IStateManagement
{
    /// <summary>Sets the state asynchronous.</summary>
    /// <param name="statusKey">The status key.</param>
    /// <param name="statusValue">The status value.</param>
    /// <returns></returns>
    public async Task<bool> SetStateAsync(string statusKey, object statusValue)
    {
        bool result = false;

        try
        {
            // custom code

            result = true;
        }
        catch (Exception stateEx)
        {
            Console.WriteLine(stateEx);
        }

        return result;
    }
    
    //...
}

Workaround

I think that the solution is not the better.

public class StateManagement() : IStateManagement
{
    /// <summary>Sets the state asynchronous.</summary>
    /// <param name="statusKey">The status key.</param>
    /// <param name="statusValue">The status value.</param>
    /// <returns></returns>
    public async Task<bool> SetStateAsync(MiniProfiler profiler, string statusKey, object statusValue)
    {
        bool result = false;

        try
        {
            using (profiler.Step("Bulk op"))
            {
                // custom code
            }
            result = true;
        }
        catch (Exception stateEx)
        {
            Console.WriteLine(stateEx);
        }

        return result;
    }
    
    //...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant