In a relationship it's always best to be open with your partner about things you do, but in order to have the best relationship possible, but there are some thoughts that it's better not to share. As a simple example of this, suppose you were kissing your boyfriend and you happened to think about some time in the past when you had kissed another boyfriend. No good will ever come from telling your boyfriend that while you were kissing him you were thinking of someone else. Perhaps that would hurt him and perhaps it would not, but there is no possible good that could come from that. Although you didn't say this, it seems like you might think that by telling your boyfriend about your crush on the coworker that you will reduce the risk that anything would ever happen between you and your coworker. I believe that if you initially tell your boyfriend about Greg then you are actually placing your relationship at more risk instead of less risk.
I think the best approach would be to not initially tell your boyfriend about your thoughts and feelings regarding your coworker (we'll call him Greg). Instead, make a resolution that you will be totally honest with your boyfriend about your actions toward Greg. If you encounter Greg in the hallway and have a five minute conversation with him then mention that to your boyfriend that evening. If you have lunch with a group of your coworkers and Greg is at the table mention that to your boyfriend. After you've mentioned Greg to your boyfriend several times he might begin to wonder if anything is going on. At that point your boyfriend might begin to ask you about Greg. At that point you could tell your boyfriend that you find Greg attractive, but that you love your boyfriend and that Greg is not a threat to your relationship. Do not share with your boyfriend that you have a crush on Greg. Continue to tell your boyfriend every time that you interact with Greg. As long as you remain totally open about your actions then your crush on Greg represents no threat to your relationship.