1

I've got a silverlight project and I'm trying to configure NLog for calling static method but it doesn't (using Nlog.config). I'm following this example. Here's Nlog.config code:

...
    <targets>
        <target name="m" xsi:type="MethodCall" 
                         className="NLogTestSilver.MainPage, NLogTestSilver"
                         methodName="LogMethod">
            <parameter layout="${level}" />
            <parameter layout="${message}" />
        </target>
    </targets>

    <rules>
        <logger name="*" minlevel="Debug" writeTo="m" />
    </rules>
...

Assembly name = NLogTestSilver.dll

Here's MainPage.xaml.cs code:

namespace NLogTestSilver
{
    public partial class MainPage : UserControl
    {
        public static Logger Logger = LogManager.GetCurrentClassLogger();
        public MainPage()
        {
            InitializeComponent();
            Logger.Fatal("Fatality");
        }
        public static void LogMethod(string level, string message)
        {
            System.Windows.Browser.HtmlPage.Window.Alert(level + " " + message);
        }
    }
}

P.S. Programmatic configuration works well.

4

1 回答 1

3

So it was found out that an exception is thrown in NLog.Targets.MethodCallTarget.InitializeTarget() method while processing className parameter.

If we change

className="NLogTestSilver.MainPage, NLogTestSilver"

to

className="NLogTestSilver.MainPage, NLogTestSilver, 
           Version=1.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxxxxxxxxx"

it works great.

Where xxxxxxxxxxxxxxxx is public key token of our assembley.

于 2013-06-11T15:39:35.913 回答