小编dar*_*hac的帖子

json 净前导零(禁用基数转换)

Json.Net 无法正确反序列化带有前导零的数字。

例如{ "number":010 }识别为 8(因为0108 基等于810 基)

如果看JsonTextReader.ParseNumber()你可以看到

long value2 = text2.StartsWith("0x", StringComparison.OrdinalIgnoreCase) ? Convert.ToInt64(text2, 16) : Convert.ToInt64(text2, 8);
Run Code Online (Sandbox Code Playgroud)

怎么可能禁用 base-cast?也许可以更换JsonTextReader

c# json json.net

4
推荐指数
1
解决办法
2280
查看次数

netcore2 控制台应用程序在 appsettings 配置日志级别

我尝试向我的控制台应用程序添加一个记录器。所有配置都正确应用,除了Logging

程序.cs:

   private static void Main(string[] args)
    {
        var services = new ServiceCollection();
        ConfigureServices(services);

        var serviceProvider = services.BuildServiceProvider();

        serviceProvider.GetService<App>().Run();
        Console.ReadKey();
    }

    private static void ConfigureServices(ServiceCollection services)
    {

        var envName = Environment.GetEnvironmentVariable("MY_ENV") ?? DevelopmentEnvName;

        var configuration = new ConfigurationBuilder()
                            .SetBasePath(Directory.GetCurrentDirectory())
                            .AddJsonFile("appsettings.json", false)
                            .AddJsonFile($"appsettings.{envName}.json", true, true)
                            .AddEnvironmentVariables()
                            .Build();

        services.AddSingleton(configuration);
        services.AddLogging(builder =>
                            {
                                builder.AddConfiguration(configuration)
                                       .AddConsole()
                                       .AddDebug();
                            });

        ConfigureOptions(services, configuration);

        ConfigureDependencies(services);
    }
Run Code Online (Sandbox Code Playgroud)

App.Run()我尝试记录调试和信息消息

 public void Run()
 {
    _logger.LogDebug("Debug");
    _logger.LogDebug(_appOptions.Env);   //print nothing

    _logger.LogInformation("Info");
    _logger.LogInformation(_appOptions.Env);  //print Info and debug env lines
 }
Run Code Online (Sandbox Code Playgroud)

appsettings.json: …

.net-core .net-core-logging .net-core-configuration .net-core-2.0

2
推荐指数
1
解决办法
1348
查看次数