-
Notifications
You must be signed in to change notification settings - Fork 147
Configure columnOptionsSection in Json doesn't work #129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I am running in to the same problem. |
I've the same problem too. I'm also using the It writes on Console and also creates the default table in SQL Server with the given name, but the UPDATE:By adding the
This is my actual
UPDATE 2018/08/22:I'm on .NET Core v2.1. |
@Luxuride the version you listed (5.1.2) doesn't have Microsoft.Extensions.Configuration support. That support was added last month (PR#123) and is currently only available in dev-release packages (at the moment, 5.1.3-dev00202). @OculiViridi are you on the SQL release package or the dev package? |
@MV10 This is all my packages versions:
I didn't know that even dev version of Serilog.Sinks.MSSqlServer was necessary. Anyway, what do you mean when you say
Because I have no problem with the code below:
UPDATE 2018/08/22:I'm on .NET Core v2.1. |
@MV10 Thanks for the tip. I installed the version you mentioned but using dev-release packages (at the moment, 5.1.3-dev00202) throws the following exception:
|
@OculiViridi Versions earlier than 5.1.3 were based upon the .NET Framework's XML-based ConfigurationManager (you can see this in the older readme which preceded my PR#123 in May that added .NET Standard multi-targeting and MS.Ext.Config v2 support). @kalexx Since that's a new problem I'd suggest a new thread with some of your details -- which .NET you're targeting, your various packages, and your config. |
Same configuration, the same problem. When switching to the dev package, get the same error: Argument value should be of type Action<>. Thanks |
Another user having the same issue with Serilog.Sinks.MSSqlServer(5.1.3-dev-00202) using .NET Core v2.1. Configuring in Startup using
And I might add that the issue that led me here was the original one from the OP: I couldn't get custom columns written to using v5.1.2. The only way I've found that works is using v5.1.3-dev-00202 and |
Everyone, please update with the .NET you're targeting -- Framework or Core? |
@MV10 I am using .NET Core 2.1 |
@MV10 Updated my posts. I'm on .NET Core v2.1. |
@MV10 Also .NET Core v2.1 |
Thanks everyone. I'll try to reproduce this today. |
Quick update, a basic .NET Core 2.1 console app is able to use the README configuration to create the database and write log entries correctly. Next I'll set up a simple ASP.NET Core test. These are the packages I'm using, I think they're equivalent to what everyone has reported above. (The last two are local builds from source pulled from the current dev branches today).
Configuration -- exactly as shown in the README (copied from the post by @paulpce above, actually) except I added Console output, and to demonstrate these other features work, {
"Serilog": {
"Using": ["Serilog.Sinks.MSSqlServer"],
"MinimumLevel": "Debug",
"WriteTo": [
"Console",
{ "Name": "MSSqlServer",
"Args": {
"connectionString": "Data Source=(LocalDB)\\MSSQLLocalDB;Initial Catalog=SerilogTest;Integrated Security=True;",
"tableName": "Logs",
"autoCreateSqlTable": true,
"columnOptionsSection": {
"removeStandardColumns": [ "Properties" ],
"customColumns": [
{ "ColumnName": "EventType", "DataType": "int", "AllowNull": false },
{ "ColumnName": "Release", "DataType": "varchar", "DataLength": 32 }
]
}
}
}
]
}
} Console program: var appConfig = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile(path: "appsettings.json", optional: false, reloadOnChange: true)
.Build();
var logConfig = new LoggerConfiguration();
logConfig.ReadFrom.Configuration(appConfig);
var logger = logConfig.CreateLogger();
logger.Information("Release is nullable {EventType} {Release}", 123, "1.0.0");
logger.Information("An Information message {EventType}", 100);
logger.Warning("A Warning message {EventType}", 200);
logger.Error("An Error message {EventType}", 300);
logger.Verbose("A Verbose message {EventType}", 400);
logger.Debug("A Debug message {EventType}", 500);
logger.Dispose(); The database it generated (the custom fields are added and the Rows written to the database: |
Also reproduced the results above using the NuGet dev packages. (Figured it can't hurt to double-check.) |
For ASP.NET Core, I suspect there is a problem with Serilog itself. Without using configuration or SQL, just logging to the console, configured in code, I get zero log output on a new template project. My test uses the following:
Configuration seems to work, SQL Server creates the table if it is missing and the correct options are applied. After calling This time I used a less complicated configuration: {
"Serilog": {
"Using": [ "Serilog.Sinks.MSSqlServer" ],
"MinimumLevel": "Debug",
"WriteTo": [
"Console",
{
"Name": "MSSqlServer",
"Args": {
"connectionString": "Data Source=(LocalDB)\\MSSQLLocalDB;Initial Catalog=SerilogTest;Integrated Security=True;",
"tableName": "Logs",
"autoCreateSqlTable": true,
"columnOptionsSection": {
"addStandardColumns": [ "LogEvent" ],
"removeStandardColumns": [ "Properties" ]
}
}
}
]
},
"AllowedHosts": "*"
} There is nothing unusual about my web host runner: public static void Main(string[] args)
{
var appConfig = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile(path: "appsettings.json", optional: false, reloadOnChange: true)
.Build();
var logConfig = new LoggerConfiguration()
.ReadFrom.Configuration(appConfig)
.CreateLogger();
Serilog.Debugging.SelfLog.Enable(Console.Error);
try
{
Log.Information("Starting web host");
CreateWebHostBuilder(args).Build().Run();
}
catch (Exception ex)
{
Log.Fatal(ex, "Web host failed");
}
finally
{
Log.CloseAndFlush();
}
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.UseSerilog(); I also tried eliminating SQL and configuration completely (I even removed the packages) and switched to configuration through code. This also does not produce any console logging at all: var logConfig = new LoggerConfiguration()
//.ReadFrom.Configuration(appConfig)
.MinimumLevel.Debug()
.WriteTo.Console()
.CreateLogger(); So I haven't been able to reproduce any of the problems in this thread, but it sure looks like something is wrong in Serilog itself. I will continue digging, it's probably some version mismatch, Microsoft put out a lot of point releases, and most of these other packages have dev or pre-release versions, too. If somebody can create a repository with a simple ASP.NET Core app that throws the configuration error, I'd like to take a look at that (e.g. start a new, blank app, and reproduce it there). |
By the way, just blindly copying the README config into an existing app will not be useful because the sample |
Ok, after fixing my embarassing cut-and-paste error, I am getting full, normal logging out of ASP.NET Core. I'm going to need someone to set up a simple reproduction app to troubleshoot any further. The logger setup should have been as follows, and then everything else works normally: // WRONG... var logConfig = new LoggerConfiguration()
Log.Logger = new LoggerConfiguration()
.ReadFrom.Configuration(appConfig)
.CreateLogger(); |
Thanks @MV10, I've just reproduced it in a clean ASP.Net Core Web app project. Versions:
(no other Nuget packages installed) Startup.cs:
appSettings.json:
I've noticed that removing I've left out the other methods in Startup.cs as they don't even get executed, the exception happens on |
@paulpce As noted in the SQL sink README, you should be using a 3.0.0-dev or newer package for Serilog.Settings.Configuration. Please bump it up and let me know if things improve. I tried a blank Edit: SelfLog messages were correct, I blanked those parts of the config but I was still using a table from an autocreate config where I'd removed the So I'm back to not seeing any issues under ASP.NET Core. |
@MV10 You were totally right about the Serilog.Settings.Configuration package. Updating that to the latest pre-release fixed it. My apologies, I totally missed that bit. Thanks for your help - looking forward to the next release. |
@paulpce No problem, glad you're back in business. I didn't expect the config package to sit in dev for so long (still relatively new to the contribution side of this ecosystem), it probably needs to be highlighted better in the readme. Is there anybody else left with issues? I'll leave this open for a few days but I suspect this was all about package versions. |
@MV10 Please refer to serilog/serilog-settings-configuration#126 (comment) for JSON configuration error that still remains... |
@OculiViridi yeah I saw that one, it's almost certainly in the SQL sink, but since you had other config issue/questions, we'll work through that one over there. |
@MV10 Ok! Thanks! |
If anyone still has issues, let me know and we can re-open this. |
@MV10 I have a corner case where I have a project using aspnetcore 2.1.3, but the target framework is .net 4.7.2 due to some legacy components. In this case, the appsettings.json column options are not applied. Since nuget defaults to use the net45 version, the compile options here change the functionality: Currenly I am including this code as a submodule, and only compiling targeting this library as netstandard2.0 which seems to work. Do know of any way around this? |
@EEParker off-hand, no, I don't know how to address that, but I will research it and let you know if I find anything. I actually thought that question would arise sooner! |
@MV10, yes, my I am using .NET Core 2.1 And these are the packages (full-list) I'm using: Microsoft.Extensions.Configuration.CommandLine "2.2.0" Config:
But I still get the Update: I updated (please let me know if you need more info) thanks! |
Now I've only a problem with the automatic creation of database. "autoCreateSqlTable": true By enabling Serilog selflog Serilog.Debugging.SelfLog.Enable(Console.Error); I see this exception:
The SQL Server I'm currently using:
|
Any news about this? Also, when will it be available the final release of this 5.1.3 version? |
I am getting this issue. I am using a dedicated external json file for the configuration. Packages: Startup: var config = new ConfigurationBuilder().AddJsonFile("somelocation").Build(); Config File:
} |
The issue happens again, the 'columnOptionsSection' doesn't work. I'm using 'Serilog.Extensions.Logging' v3.0.1 and 'Serilog.Sinks.MSSqlServer' v5.1.2 [UPDATE] |
I am used CREATE TABLE [dbo].[LogsTest]( { I can't write log to MSSQL when i using serilog with the table name different the default value. If i set default value, it is okay. |
Uh oh!
There was an error while loading. Please reload this page.
I have serilog config in Json. When I'm trying to add/remove columns, nothing happens.
Dependencies
logsettings.json have Copy always (After config change Clean -> Rebuild)
Calling config
Config
Even config template did not work
In database are always these columns (None is added/removed)
The text was updated successfully, but these errors were encountered: