【发布时间】:2018-08-01 11:15:08
【问题描述】:
我正在尝试在 Azure 函数中使用除标准 Tracewriter 之外的另一个记录器。大多数 NLog 在运行 Azure 函数时都在本地工作,但在我部署到 Azure 后什么都没有写入。
通过 blob 加载配置。我将配置文件存储在存储 blob 中并将其作为参数加载
[FunctionName("Update")]
public static IActionResult Run([HttpTrigger(AuthorizationLevel.Function, "put", Route = null)]HttpRequest req,
[Blob("nlog/nlog.config", FileAccess.Read)] string inputBlob)
Logger.LoadConfiguration(inputBlob);
Logger.Info("This does not show in Azure");
...
我加载配置的记录器类
public class Logger
{
public static Logger Log = LogManager.GetCurrentClassLogger();
private static bool _isConfigrued;
public static void LoadConfiguration(string xmlString)
{
if (string.IsNullOrEmpty(xmlString))
return;
if (!_isConfigrued)
{
StringReader sr = new StringReader(xmlString);
XmlReader xr = XmlReader.Create(sr);
LogManager.Configuration = new XmlLoggingConfiguration(xr, null);
Log = LogManager.GetCurrentClassLogger();
_isConfigrued = true;
}
}
}
然后我将 NLog 配置为写入跟踪
<targets>
<target name='console' type='Console' layout='Console ${message}' />
<target name="trace" xsi:type="Trace" layout="Trace ${message}" />
</targets>
<rules>
<logger name="*" minlevel="Trace" writeTo="trace" />
<logger name="*" minlevel="Trace" writeTo="console" />
</rules>
但是没有任何东西被写入跟踪/控制台
我也尝试加载此处建议的配置
https://blogs.msdn.microsoft.com/waws/2017/03/16/nlog-and-database/
也不行
我还尝试了Microsoft.Extentions.Loggin.Ilogger,在本地工作,但在 Azure 上没有打印任何内容。
不会抛出异常,只是清空控制台窗口。
【问题讨论】:
-
如果您在
app.config中配置它,这将不起作用,因为函数不使用该文件。 -
我从 blob 存储或文件系统和链接中加载配置文件
-
您在哪里检查您的日志?在 Functions 门户中,您看到的日志是从文件系统流式传输的日志,而不是来自控制台日志。
-
我在这里读到了目标 xsi:type"Trace" 将进入流媒体。就像原来的tracewriter一样
-
我可以确认,对于 v2,使用
TraceWriter不会向 Azure 门户中的控制台输出任何内容。
标签: c# .net-core azure-functions nlog