我有一个简单的Azure函数,我希望能够在流日志窗口和Application Insights中监控日志输出。
到目前为止,我可以在应用程序洞察中看到NLog输出,但在流窗口中看不到。Microsoft ILogger输出同时出现在这两个文件中。
以下是我到目前为止所做的工作:
从Azure门户创建了一个基本的Azure测试函数
{ "version":"2.0","logging":{ "logLevel":{ "default":"Trace“}
到目前为止,结果是:
这是最终的函数代码...
public static class Function1
{
[FunctionName("LogTest")]
public static void Run([TimerTrigger("0 */5 * * * *")] TimerInfo myTimer, ILogger log)
{
// Set up NLOG targets and logger
var config = new LoggingConfiguration();
//send logging to application insights
config.LoggingRules.Add(
new LoggingRule("*", LogLevel.Trace,
new ApplicationInsightsTarget()));
//also try to log to Trace output
//'RawWrite' is used to try and force output at all log-levels
config.LoggingRules.Add(
new LoggingRule("*", LogLevel.Trace,
new TraceTarget {RawWrite = true}));
LogManager.Configuration = config;
var nlog = LogManager.GetLogger("Example");
//log using native
log.LogInformation($"log:Info"); //appears in live-stream, app-insights
log.LogError("log:Error"); //appears in live-stream, app-insights
log.LogTrace("log:Trace"); //appears in live-stream, app-insights (after modifying host.json)
//log using nlog
nlog.Info("nlog:info"); //appears in ........... app-insights
nlog.Error("nlog:error"); //appears in ........... app-insights
nlog.Trace("nlog:trace"); //appears in ........... app-insights
//say goodbye
log.LogInformation("log:ending");
}
}
提前感谢您的建议--毫无疑问,我遗漏了一些简单的步骤。
https://stackoverflow.com/questions/56254964
复制相似问题