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

Microsoft Orleans - Logging for Record type #9285

Open
selvakumar-arc opened this issue Jan 16, 2025 · 1 comment
Open

Microsoft Orleans - Logging for Record type #9285

selvakumar-arc opened this issue Jan 16, 2025 · 1 comment

Comments

@selvakumar-arc
Copy link

Hi,
I am trying to implement logging to Microsoft Orleans (new to Orleans) project but getting error. Please help me how to implement logging. Attaching my sample code for reference.

Option 1
public record GetMyCalculation(MyRequest request, ILogger logger) : BaseCalculation
{
public override MyResponse Calculate()
{
MyResponse response = new MyResponse();

    try
    {
	    logger.LogError("errrrrorrr");
		response.IsSuccess = true;
        response.Message = "Success!";
    }
    catch (Exception ex)
    {
        response.IsSuccess = false;
        response.Message = ex.Message;
       
    }

    return response;
}

}

Getitng error - Error (active) CA1848 For improved performance, use the LoggerMessage delegates.

Option 2
public record GetMyCalculation(MyRequest request, ILogger logger) : BaseCalculation
{
public override MyResponse Calculate()
{
MyResponse response = new MyResponse();

    try
    {
	    LogErrors("errrrrorrr");
		response.IsSuccess = true;
        response.Message = "Success!";
    }
    catch (Exception ex)
    {
        response.IsSuccess = false;
        response.Message = ex.Message;
       
    }

    return response;
}

[LoggerMessage(LogLevel.Error, Message = "There was an error occurred in Calculation. {message}.")]
public partial void LogErrors(string message);

}

Getting error like
Error (active) CS8795 Partial method 'GetMyCalculation.LogErrors(string)' must have an implementation part because it has accessibility modifiers.
Error (active) CA1822 Members that do not access instance data or call instance methods can be marked as static. After you mark the methods as static, the compiler will emit nonvirtual call sites to these members. This can give you a measurable performance gain for performance-sensitive code.

Thank you!
Selvakumar R

@ledjon-behluli
Copy link
Contributor

@selvakumar-arc this has nothing to do with Orleans, its the c# compiler telling you that you have errors in your code, but here is the correct version if you want to use it:

public partial record GetMyCalculation(MyRequest request, ILogger logger) : BaseCalculation
{
    public override MyResponse Calculate()
    {
        MyResponse response = new MyResponse();

        try
        {
            LogErrors(logger, "errrrrorrr");
            response.IsSuccess = true;
            response.Message = "Success!";
        }
        catch (Exception ex)
        {
            response.IsSuccess = false;
            response.Message = ex.Message;
        }

        return response;
    }

    [LoggerMessage(LogLevel.Error, Message = "There was an error occurred in Calculation. {message}.")]
    static partial void LogErrors(ILogger logger, string message);
}

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

2 participants