【问题标题】:Use a class on azure and on a other app: monitoring dilemma在 azure 和其他应用程序上使用类:监控困境
【发布时间】:2012-06-28 09:52:42
【问题描述】:

首先,我是 C# 的初学者,没有太多程序员的习惯。

我想在 Windows azure 和控制台应用程序上使用相同的类。
比如这个:

public static class Conversion
{
    public static void Convert(string fileName)
    {
        // ...
        if (error)
            Console.WriteLine("It is a error in Conversion.Convert(string).");
        // ...
        Console.WriteLine("Conversion success !");
    }
}

但是,在 azure 的控制台上显示并不是很有用。我想创建一个接口和它的 2 个实现。

public interface ILog
{
    void Write(string str);
    void WriteLinge(string str);
}

public static class LogAzure : ILog
{
    public static void WriteLine(string str)
    {
        Trace.WriteLine(str);
    }

}


public static class LogConsole : ILog
{
    public static void WriteLine(string str)
    {
        Console.WriteLine(str);
    }
}

所以在我的转换方法中我必须使用 ILog.WriteLine()。

问题:
首先 - 也是更重要的 - 这是一个好主意/做法吗?

如果是:
如何知道我是否在 Azure 中? (RoleEnvironment.IsAvailable??)
如何使用 LogAzure 或 LogConsole ? (对我的方法有争论?)

【问题讨论】:

    标签: c# logging azure console-application monitoring


    【解决方案1】:

    您应该在这两种情况下都使用 Trace。将控制台应用配置为使用ConsoleTraceListener,将Azure 版本配置为使用Azure diagnostics

    【讨论】:

    • 好的,它工作正常。我是 C# 的初学者,我不知道所有这些小技巧,但我看到它提供了一个有用的 API! :) 谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-09
    • 1970-01-01
    • 2021-04-09
    • 1970-01-01
    • 2012-07-16
    • 2010-10-03
    相关资源
    最近更新 更多