Silverlight:Log4Net 到隔离存储

发布于 2024-08-24 04:38:19 字数 468 浏览 5 评论 0原文

首先,我了解 Clog,并且我不想实现这一部分。原因是什么?我们无法维护严格的日志记录“框架”。

所以我的问题是:

是否可以在 Silverlight 应用程序中实现 log4net ?我想要实现的是登录到独立存储。我知道,只有 1 MB 的可用存储空间,但这个限制可以增加(用户必须接受这一点,我也知道)。 顺便说一句,请不要向我提供替代方案。我只想知道是否有人实现了 log4net 到隔离存储。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

要走干脆点 2024-08-31 04:38:19

这就是我所做的..

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
}

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
}
情绪少女 2024-08-31 04:38:19

我无法想象这是可能的。您必须下载 log4net 源代码并尝试针对 silverlight 运行时进行编译。我想也许可以调整部分代码并使其在 silverlight 中构建,但这听起来像是一项艰巨的工作。您最好推出自己的解决方案,或使用 CLog(哎呀)。

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

柠檬色的秋千 2024-08-31 04:38:19

Microsoft Enterprise Library 5.0 的日志应用程序块现在可用于 Silverlight。查看 Silverlight 集成包 和相应的演示

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文