Event Handler for publish:end event is just hitting the first selected language. Any idea?
<p>I made an event handler for the <em>publish:end</em> event in order to create a Sitemap XML file for each language available in my Sitecore instance every time Sitecore finishes publishing the site. </p>

<p>As described in <a href="https://stackoverflow.com/questions/12698876">Get Languages chosen for publish in publish:end event</a>:</p>

<blockquote>
  <p>[...] actually the publish:end event hits once for every language - and you get get the language that is being published by doing EventArgs[0].Options.Language.</p>
</blockquote>

<p>The problem is <em>publish:end</em> event is just hitting my event handler once and for the first selected language only. If I select 3 languages (En-US, Pt-BR, Fr-CA) during the publishing of my Sitecore instance, for example, <em>publish:end</em> event will hit my event handler one time just and display <strong>En-US</strong> as the value of the Property <code>EventArgs[0].Options.Language</code>. It does not hit my event handler for the other 2 selected languages (Pt-BR, Fr-CA).</p>

<p>I am using <strong>Sitecore.NET 8.0 (rev. 150812)</strong>.</p>

<p>Below is my configuration file for the event handler:</p>

<pre><code>&lt;?xml version="1.0"?&gt;
&lt;configuration xmlns:patch="http://www.sitecore.net/xmlconfig/"&gt;
    &lt;sitecore&gt;
        &lt;events&gt;
            &lt;event name="publish:end"&gt;
                &lt;handler type="Project1.EventHandlers.BuildXMLSitemap, Project1.SBL" method="BuildSitemap" /&gt;
            &lt;/event&gt;
      &lt;event name="publish:end:remote"&gt;
        &lt;handler type="Project1.EventHandlers.BuildXMLSitemap, Project1.SBL" method="BuildSitemap" /&gt;
      &lt;/event&gt;
    &lt;/events&gt;

    &lt;!-- Update settings for the Trusted_Connection = True --&gt;
    &lt;sites&gt;

      &lt;site name="website"&gt;
        &lt;patch:attribute name="sitemapXmlFileName"&gt;sitemap&lt;/patch:attribute&gt;
        &lt;patch:attribute name="sitemapXmlIndexFileName"&gt;sitemapindex&lt;/patch:attribute&gt;
      &lt;/site&gt;

    &lt;/sites&gt;
    &lt;/sitecore&gt;
&lt;/configuration&gt;
</code></pre>

<p>And below is my code:</p>

<pre><code>namespace Project1.EventHandlers
{
    public class BuildXMLSitemap
    {

        public void BuildSitemap(object sender, EventArgs args)
        {

            Language language = GetLanguage(args);              

        }

        private Language GetLanguage(EventArgs args)
        {
            Language language;
            if (args is PublishEndRemoteEventArgs)
            {
                var publishArgs = args as PublishEndRemoteEventArgs;
                language = LanguageManager.GetLanguage(publishArgs.LanguageName);
            }
            else
            {
                var publisher = Event.ExtractParameter(args, 0) as Publisher;
                if (publisher == null) return null;
                language = publisher.Options.Language;
            }

            return language;
        }

    }

}
</code></pre>

<p>And here is my Sitecore instance with the languages configured:</p>

<p><a href="https://i.stack.imgur.com/3QNoZ.png" rel="nofollow noreferrer">Sitecore Languages Configured</a></p>

<p>And here is Sitecore Publish Site Dialog showing the available languages:</p>

<p><a href="https://i.stack.imgur.com/qalpa.png" rel="nofollow noreferrer">Publish Site Dialog</a></p>