Grant execute on xp_logevent to sa using sa user to do it
How can I grant execute permissions to sa user?


You don't need to grant execute anything to sa as sa is in the sysadmin server role and can pretty much do anything. Hence, if you are getting an error executing xp_logevent, then you aren't logging in as sa. Is the connection string using context connection = true; or a regular / external connection? If using context connection = true; then the permissions are based on whoever is executing the SQLCLR stored procedure. If using a regular connection, the permissions are based on the logon account for the SQL Server NT Service (MSSQLSERVER / SQLEXPRESS if it is a default instance) by default, else it can be the permissions of whoever is executing the SQLCLR stored procedure if code has been added to do impersonation.

So, how is the SqlConnection being made? The answer to that question will help determine the appropriate fix. If this SQLCLR stored procedure is to be called by anyone (meaning, Users who are not necessarily in the db_owner database role or the sysadmin server role), then you can do the following to grant this permission to the smallest scope possible.

In the database that contains the SQLCLR stored procedure:


Create an Asymmetric Key (see CREATE ASYMMETRIC KEY)
Create a User from that Asymmetric Key (see CREATE USER)
Add this new User to the db_owner Database Role
Create a T-SQL Stored Procedure (maybe call it dbo.LogEvent) that accepts the two parameters you are passing in (@errorNumber and @message) and simply executes EXEC xp_logevent @errorNumber, @message, informational;
Grant EXECUTE on this new Stored Procedure to any Users and/or Database Roles that will be calling the SQLCLR Stored Procedure
Sign this new Stored Procedure with the same Asymmetric Key used to create the new User (see ADD SIGNATURE)
Update your SQLCLR code to execute this new T-SQL Stored Procedure (i.e. dbo.LogEvent) instead of xp_logevent


You can then change your using statement to have new SqlCommand("dbo.LogEvent", connection)
then change cmd.CommandType = CommandType.Text; to be cmd.CommandType = CommandType.StoredProcedure;
remove the const string executeLog line



Other notes:


Please do not use AddWithValue as there are issues with it. Instead, just create the SqlParameter with an explicitly set datatype and then add it to the SqlCommand.SqlParameters collection.
No need to call ExecuteScalar if you are not capturing something from a result set. Instead, call ExecuteNonQuery