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,第1张

概述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 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 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 = "${specialfolder:Mydocuments}/log.${shortdate}.txt",Layout = new CsvLayout()            {                Columns =                {                    new CsvColumn("Time","${longdate}"),new CsvColumn("Level","${level}"),new CsvColumn("Lessage","${message}"),new CsvColumn("Logger","${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("Page loaded");        this.LayoutUpdated += (sender,e) => logger.DeBUG("Layout updated");        this.SizeChanged += (sender,e) => logger.DeBUG("Size changed to {0}x{1}",e.NewSize.WIDth,e.NewSize.Height);        this.KeyDown += (sender,e) => logger.DeBUG("Key down '{0}'",e.Key);        this.Unloaded += (sender,e) => logger.Info("Unloaded");    }    private voID button1_Click(object sender,RoutedEventArgs e)    {        logger.Info("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所遇到的程序开发问题。

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

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1021519.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-23
下一篇2022-05-23

发表评论

登录后才能评论

评论列表(0条)

    保存