我目前正在使用 Serilog 实现 Azure Application Insights 日志记录,除非我在 Serilog 配置中使用输出模板,否则该日志记录工作正常。将 Serilog 数据传递给应用程序洞察时,模板似乎被忽略了。
我在 appsetting.json 中的 serilog 配置:
"Serilog": {
"Using": [ "Serilog.Sinks.ApplicationInsights" ],
"MinimumLevel": "Debug",
"WriteTo": [
{ "Name": "Console" },
{
"Name": "RollingFile",
"Args": {
"pathFormat": "logs\\log-{Date}.txt",
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level}] {Message}{NewLine}{Exception}"
}
},
{
"Name": "ApplicationInsights",
"Args": {
"restrictedToMinimumLevel": "Information",
"telemetryConverter": "Serilog.Sinks.ApplicationInsights.Sinks.ApplicationInsights.TelemetryConverters.TraceTelemetryConverter, Serilog.Sinks.ApplicationInsights",
"outputTemplate": "Test Template - {Message}"
}
}
],
"Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId" ],
"Properties": {
"Application": "app"
}
},
Run Code Online (Sandbox Code Playgroud)
日志记录语句:
logger.Error("Test Serilog Error For …
logging azure serilog azure-application-insights asp.net-core
我为类活动编写了以下程序,提示用户输入0到100之间的无限量测试标记,当用户输入该范围之外的标记时,它应该告诉用户它的无效(到目前为止我的程序中有效) ).当用户输入"-1"时,它应该停止程序,然后打印出那些标记的平均值.
import java.util.*;
public class HmWk62 {
static Scanner console = new Scanner(System.in);
public static void main(String[] args) {
int count=1;
int mark, total=0;
double average;
System.out.println("please enter mark "+count);
mark = console.nextInt();
count++;
while ((mark >= 0)&&(mark <= 100)){
System.out.println("Please enter mark "+count);
mark = console.nextInt();
total += mark ;
++count;
while ((mark < 0)||(mark > 100)){
System.out.println("Invalid mark, please re-enter");
mark = console.nextInt();
}
}
}
}
Run Code Online (Sandbox Code Playgroud)