以下是我所做的事情:
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
}
我无法想象这是可能的。你需要下载log4net源码,并尝试使用silverlight运行时进行编译。我想可能有可能适应部分代码并使其在silverlight中构建,但听起来是非常艰难的工作。你可能最好自己制定解决方案,或者使用CLog(糟糕的选择)。