SharePoint 2010 | Get Solution File Name from Feature activated

I was working on a custom solution with a client. This project has a high level of custom auditing, which means any custom feature being activated or deactivated, any solution being added/retracted etc. is logged.

As part of the logging they also log the name of the solution file in question. They have multiple Farm solutions and sandbox solutions.

As part of feature activated/Installed, I had to find the solution file name of which the feature was a part of.

The following code helped me do this:

public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            SPSite site = (SPSite)properties.Feature.Parent;
            string solutionName = site.WebApplication.Farm.Solutions[properties.Feature.Definition.SolutionId].SolutionFile.DisplayName;
            //Log the namespace ToString the logging DB
        }