Question

First, I know about Clog, and I do not want to implement this piece. The reason? We can't maintain severeal logging 'frameworks'.

So to my question:

Is it possible to implement log4net in a Silverlight application? What I want to achieve is logging to the Isolated Storage. I know, there's only 1 MB of storage available, but this limit can be increased (the user has to accept this, I know too). By the way, please don't provide me alternatives. I do only want to know if somebody implemented a log4net to isolated storage.

Was it helpful?

Solution

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).

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top