NLog / NLog.Web

NLog integration for ASP.NET & ASP.NET Core 2-8
https://nlog-project.org
BSD 3-Clause "New" or "Revised" License
320 stars 166 forks source link

Installing targets does not work #780

Closed Giant150 closed 2 years ago

Giant150 commented 2 years ago

Hi! Thanks for reporting this feature/bug/question!

Please keep / fill in the relevant info from this template so that we can help you as best as possible.

QUESTIONS are preferred on StackOverflow. You could expect a faster response there (but do include all the info below). Use the tag "nlog" https://stackoverflow.com/questions/ask

Please only post issues here related to NLog.Web. If unsure, please post on https://github.com/NLog/NLog/issues/new

For .NET Core users, please check the platform support: https://github.com/NLog/NLog/wiki/platform-support

Type (choose one):

NLog version: 5.0

NLog.Web/NLog.Web.AspNetCore version: 5.0

NLog.Extensions.Logging version: 5.0

Platform:.NET Core 6

Current NLog config (xml or C#, if relevant)

<target xsi:type="Database" name="database" dbProvider="Microsoft.Data.SqlClient.SqlConnection, Microsoft.Data.SqlClient">
      <connectionString>${configsetting:ConnectionStrings.GDbContext}</connectionString>
      <install-command>
        <text>
          <!-- NOTE: call LogManager.Configuration.Install(new InstallationContext()); to execute this query. -->
          IF OBJECT_ID('dbo.Sys_Log${date:format=yyyyMMdd}', 'U') IS NULL
          CREATE TABLE dbo.Sys_Log${date:format=yyyyMMdd} (
          [Id] nvarchar(50) NOT NULL,
          [CreateTime] datetime2 NOT NULL,
          [AppName] nvarchar(50) NOT NULL,
          [Level] nvarchar(50) NOT NULL,
          [Logger] nvarchar(100) NULL,
          [Msg] nvarchar(max) NULL,
          [Exception] nvarchar(max) NULL,
          [UserId] nvarchar(50) NULL,
          [Url] nvarchar(500) NULL,
          [IP] nvarchar(50) NULL,
          CONSTRAINT [PK_Sys_Log${date:format=yyyyMMdd}] PRIMARY KEY ([Id])
          );
        </text>
      </install-command>
      <commandText>
        INSERT INTO [dbo].[Sys_Log${date:format=yyyyMMdd}]([Id], [CreateTime], [AppName], [Level], [Logger], [Msg], [Exception], [UserId], [Url], [IP])
        VALUES (@Id, @CreateTime, @AppName, @Level, @Logger, @Msg, @Exception, @UserId, @Url, @IP);
      </commandText>
      <parameter name="@Id" layout="${ticks}${sequenceid:padCharacter=0:padding=5:fixedLength=true:alignmentOnTruncation=right}" />
      <parameter name="@CreateTime" layout="${longdate}" />
      <parameter name="@AppName" layout="${var:AppName}" />
      <parameter name="@Level" layout="${level}" />
      <parameter name="@Logger" layout="${logger}" allowDbNull="true" />
      <parameter name="@Msg" layout="${message}" allowDbNull="true" />
      <parameter name="@Exception" layout="${exception:format=tostring}" allowDbNull="true" />
      <parameter name="@UserId" layout="${aspnet-user-claim:userId}" allowDbNull="true" />
      <parameter name="@Url" layout="${aspnet-request-url}" allowDbNull="true" />
      <parameter name="@IP" layout="${aspnet-request-ip}" allowDbNull="true" />
    </target>

In case of a BUG:

Not working properly after upgrading to the latest version

In case of a FEATURE REQUEST:

snakefoot commented 2 years ago

Maybe it is caused by this breaking change : NLog Targets extracted into their own nuget-packages

Does it work if you add NLog.Database-nuget-package to your application?

Giant150 commented 2 years ago

tks Problem solved after add NLog.Database to app

snakefoot commented 2 years ago

Excellent. Closing issue as resolved.