Silverlight: Log4Net to Isolated Storage

 ̄綄美尐妖づ 提交于 2019-12-04 12:57:42

I cannot imagine that it is possible. You would have to download the log4net source and try to compile it against the silverlight runtime. I suppose it may be possible to adapt parts of the code and make it build in silverlight, but that sounds like a lot of hard work. You are probably better off rolling your own solution, or using CLog (whoops).

Christian Casutt

Here's what I've done..

using System.IO.IsolatedStorage;
using System.IO;

namespace Solution.Silverlight.Classes
{
    public static class Logging
    {
        public static void Log(string message, LOGLEVEL logLevel)
        {
            try
            {
                using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication())
                {
                    using (Stream stream = new IsolatedStorageFileStream("Solution.Silverlight.log", FileMode.Append, FileAccess.Write, store))
                    {
                        StreamWriter writer = new StreamWriter(stream);
                        switch (logLevel)
                        {
                            case LOGLEVEL.INFO:
                                writer.Write(String.Format("{0:u} [INFO] {1}{2}", DateTime.Now, message,Environment.NewLine));
                                break;
                            case LOGLEVEL.WARNING:
                                writer.Write(String.Format("{0:u} [WARNING] {1}{2}", DateTime.Now, message, Environment.NewLine));
                                break;
                            case LOGLEVEL.ERROR:
                                writer.Write(String.Format("{0:u} [ERROR] {1}{2}", DateTime.Now, message, Environment.NewLine));
                                break;
                            case LOGLEVEL.FATAL:
                                writer.Write(String.Format("{0:u} [FATAL] {1}{2}", DateTime.Now, message, Environment.NewLine));
                                break;
                            default:
                                break;
                        }
                        writer.Close();
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }
    }
}


public enum LOGLEVEL
{
    INFO,
    WARNING,
    ERROR,
    FATAL
}

The Logging Application Block of Microsoft Enterprise Library 5.0 is now available for Silverlight. Take a look at the Silverlight Integration Pack and the corresponding demo.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!