silverlight   发布时间:2022-05-03  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了NLog 2.0 for Silverlight 4 and .NET Framework 4.0 preview builds大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

NLog 2.0 for Silverlight 4 and .NET Framework 4.0 preview builds April 16, 2010   Tweet This week .NET Framework 4.0 and Silverlight 4 have been released. I’ve updated NLog 2.0 to support them and pub

NLog 2.0 for Silverlight 4 and .NET Framework 4.0 preview builds

 

This week .NET Framework 4.0 and Silverlight 4 have been released. I’ve updated NLog 2.0 to support them and published a new build – very experimental – on CodePlex. One of the biggest updates in Silverlight 4 is support for out-of-browser applications with elevated permissions,which means applications that can access the filesystem.

I’ve put together a Tiny sample that shows how to use NLog in Silverlight application. Basically since Silverlight does not have a concept of application configuration file you should configure Silverlight at application startup. In my case I’ve added this code in App.xaml.cs:

private void Application_Startup(object sender,StartupEventArgs E)
{
    InitializeNLog();
    this.RootVisual = new MainPage();
}

private void InitializeNLog()
{
    SimpleConfigurator.ConfigureForTargetLogging(
        new FileTarget()
        {
            Filename = @H_404_42@"${specialfolder:MyDocuments}/log.${shortdatE}.txt",Layout = new CsvLayout()
            {
                columns =
                {
                    new Csvcolumn(@H_404_42@"Time",@H_404_42@"${longdatE}"),new Csvcolumn(@H_404_42@"Level",@H_404_42@"${level}"),new Csvcolumn(@H_404_42@"Lessage",@H_404_42@"${messagE}"),new Csvcolumn(@H_404_42@"Logger",@H_404_42@"${logger}"),},}
        },LogLevel.Debug);
}

The application will produce CSV-formatted log file in Documents folder. The name of the file will be log.CURRENTDATE.txt.

Usage of NLog stays unchanged:

public partial class MainPage : UserControl
{
    private static Logger logger = LogManager.GetCurrentClassLogger();

    public MainPage()
    {
        InitializeComponent();

        // log some events
        this.Loaded += (sender,E) => logger.Info(@H_404_42@"Page loaded");
        this.Layoutupdated += (sender,E) => logger.Debug(@H_404_42@"Layout updated");
        this.SizeChanged += (sender,E) => logger.Debug(@H_404_42@"Size changed to {0}x{1}",e.NewSize.Width,e.NewSize.Height);
        this.KeyDown += (sender,E) => logger.Debug(@H_404_42@"Key down '{0}'",e.Key);
        this.Unloaded += (sender,E) => logger.Info(@H_404_42@"Unloaded");
    }

    private void button1_Click(object sender,RoutedEventArgs E)
    {
        logger.Info(@H_404_42@"Button clicked");
    }
}

大佬总结

以上是大佬教程为你收集整理的NLog 2.0 for Silverlight 4 and .NET Framework 4.0 preview builds全部内容,希望文章能够帮你解决NLog 2.0 for Silverlight 4 and .NET Framework 4.0 preview builds所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。