NLog adding a database schema name












1















I am unsure if its possible to add a database schema to NLog. I have tried this method:



<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
autoReload="true"
internalLogLevel="Info"
internalLogFile="C:tempinternallog.txt">
<targets>
<target name="logfile" xsi:type="File"
fileName="C:temp/${shortdate}_logfile.txt"
layout="${longdate} ${level:uppercase=true} ${message}"/>


<target xsi:type="Database" name="database"
connectionString="Server=.SQLEXPRESS;Database=AppDB;Trusted_Connection=True;MultipleActiveResultSets=true;User Id=AppDBUser;Password=PSSWRD!"
commandType="StoredProcedure"
commandText="[AppDB].[ASTONE.EventLogs]">
<parameter name="@message" layout="${message}" />
<parameter name="@level" layout="${level}" />
<parameter name="@logger" layout="${logger}" />
<!--<dbProvider>System.Data.SqlClient</dbProvider>-->
</target>
</targets>
<rules>
<logger name="*" minlevel="Info" writeTo="logfile" />
<logger name="*" minlevel="Info" writeTo="database" />
</rules>
</nlog>


However, this gives me this error:




Error DatabaseTarget(Name=database): Error when writing to database.
Exception: System.Data.SqlClient.SqlException (0x80131904): Could not
find stored procedure 'AppDB.ASTONE.EventLogs'.




I have looked through the NLog wiki but it doesn't seem to have anything as well.










share|improve this question



























    1















    I am unsure if its possible to add a database schema to NLog. I have tried this method:



    <?xml version="1.0" encoding="utf-8" ?>
    <nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    autoReload="true"
    internalLogLevel="Info"
    internalLogFile="C:tempinternallog.txt">
    <targets>
    <target name="logfile" xsi:type="File"
    fileName="C:temp/${shortdate}_logfile.txt"
    layout="${longdate} ${level:uppercase=true} ${message}"/>


    <target xsi:type="Database" name="database"
    connectionString="Server=.SQLEXPRESS;Database=AppDB;Trusted_Connection=True;MultipleActiveResultSets=true;User Id=AppDBUser;Password=PSSWRD!"
    commandType="StoredProcedure"
    commandText="[AppDB].[ASTONE.EventLogs]">
    <parameter name="@message" layout="${message}" />
    <parameter name="@level" layout="${level}" />
    <parameter name="@logger" layout="${logger}" />
    <!--<dbProvider>System.Data.SqlClient</dbProvider>-->
    </target>
    </targets>
    <rules>
    <logger name="*" minlevel="Info" writeTo="logfile" />
    <logger name="*" minlevel="Info" writeTo="database" />
    </rules>
    </nlog>


    However, this gives me this error:




    Error DatabaseTarget(Name=database): Error when writing to database.
    Exception: System.Data.SqlClient.SqlException (0x80131904): Could not
    find stored procedure 'AppDB.ASTONE.EventLogs'.




    I have looked through the NLog wiki but it doesn't seem to have anything as well.










    share|improve this question

























      1












      1








      1








      I am unsure if its possible to add a database schema to NLog. I have tried this method:



      <?xml version="1.0" encoding="utf-8" ?>
      <nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      autoReload="true"
      internalLogLevel="Info"
      internalLogFile="C:tempinternallog.txt">
      <targets>
      <target name="logfile" xsi:type="File"
      fileName="C:temp/${shortdate}_logfile.txt"
      layout="${longdate} ${level:uppercase=true} ${message}"/>


      <target xsi:type="Database" name="database"
      connectionString="Server=.SQLEXPRESS;Database=AppDB;Trusted_Connection=True;MultipleActiveResultSets=true;User Id=AppDBUser;Password=PSSWRD!"
      commandType="StoredProcedure"
      commandText="[AppDB].[ASTONE.EventLogs]">
      <parameter name="@message" layout="${message}" />
      <parameter name="@level" layout="${level}" />
      <parameter name="@logger" layout="${logger}" />
      <!--<dbProvider>System.Data.SqlClient</dbProvider>-->
      </target>
      </targets>
      <rules>
      <logger name="*" minlevel="Info" writeTo="logfile" />
      <logger name="*" minlevel="Info" writeTo="database" />
      </rules>
      </nlog>


      However, this gives me this error:




      Error DatabaseTarget(Name=database): Error when writing to database.
      Exception: System.Data.SqlClient.SqlException (0x80131904): Could not
      find stored procedure 'AppDB.ASTONE.EventLogs'.




      I have looked through the NLog wiki but it doesn't seem to have anything as well.










      share|improve this question














      I am unsure if its possible to add a database schema to NLog. I have tried this method:



      <?xml version="1.0" encoding="utf-8" ?>
      <nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      autoReload="true"
      internalLogLevel="Info"
      internalLogFile="C:tempinternallog.txt">
      <targets>
      <target name="logfile" xsi:type="File"
      fileName="C:temp/${shortdate}_logfile.txt"
      layout="${longdate} ${level:uppercase=true} ${message}"/>


      <target xsi:type="Database" name="database"
      connectionString="Server=.SQLEXPRESS;Database=AppDB;Trusted_Connection=True;MultipleActiveResultSets=true;User Id=AppDBUser;Password=PSSWRD!"
      commandType="StoredProcedure"
      commandText="[AppDB].[ASTONE.EventLogs]">
      <parameter name="@message" layout="${message}" />
      <parameter name="@level" layout="${level}" />
      <parameter name="@logger" layout="${logger}" />
      <!--<dbProvider>System.Data.SqlClient</dbProvider>-->
      </target>
      </targets>
      <rules>
      <logger name="*" minlevel="Info" writeTo="logfile" />
      <logger name="*" minlevel="Info" writeTo="database" />
      </rules>
      </nlog>


      However, this gives me this error:




      Error DatabaseTarget(Name=database): Error when writing to database.
      Exception: System.Data.SqlClient.SqlException (0x80131904): Could not
      find stored procedure 'AppDB.ASTONE.EventLogs'.




      I have looked through the NLog wiki but it doesn't seem to have anything as well.







      asp.net logging asp.net-core nlog






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Dec 28 '18 at 23:27









      JianYAJianYA

      6261125




      6261125
























          1 Answer
          1






          active

          oldest

          votes


















          3














          This is from memory, but I think your commandText value would need to be this:



          commandText="[ASTONE].[EventLogs]"


          The separating . needs to be outside the square brackets.



          Since you specify the database name in the connection string, you shouldn't need it as part of the command text.



          UPDATED WITH NEW INFORMATION



          Since ASTONE.EventLogs is a table, you will need to write a stored procedure to insert your parameter values into it. That's your missing piece.



          Here's an example stored procedure:



          CREATE PROC [ASTONE].[LogEvent] 
          (
          @message nvarchar(max),
          @level int,
          @logger nvarchar(1024)
          )
          AS
          INSERT INTO [ASTONE].[EventLogs]
          ( message, level, logger )
          VALUES( @message, @level, @logger)


          I am guessing about the layout of your EventLogs table and the types and definitions of the parameters.



          And then your commandText attribute would look like this:



           commandText="[ASTONE].[LogEvent]"





          share|improve this answer


























          • Hi! Thank you so much for replying. Unfortunately when I try your method I get this error: Exception: System.Data.SqlClient.SqlException (0x80131904): The request for procedure 'EventLogs' failed because 'EventLogs' is a table object.

            – JianYA
            Dec 29 '18 at 0:13











          • AH! Then that is your core problem. (I wondered whether EventLogs was a stored proc: it sounded like a table name!)

            – Ann L.
            Dec 29 '18 at 0:19











          • NLog uses a SqlCommand object. That represents a call to a stored procedure, or (sometimes) a SQL insert or update statement.

            – Ann L.
            Dec 29 '18 at 0:20











          • You will need to write a stored procedure that takes your parameters and inserts records into EventLogs, and put that procedure's name in the commandText tag.

            – Ann L.
            Dec 29 '18 at 0:20













          • Hi! Thanks for helping. I have another question. Do I just put that as a comment? I'm unsure of where to put the command

            – JianYA
            Dec 29 '18 at 0:41











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53965379%2fnlog-adding-a-database-schema-name%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          3














          This is from memory, but I think your commandText value would need to be this:



          commandText="[ASTONE].[EventLogs]"


          The separating . needs to be outside the square brackets.



          Since you specify the database name in the connection string, you shouldn't need it as part of the command text.



          UPDATED WITH NEW INFORMATION



          Since ASTONE.EventLogs is a table, you will need to write a stored procedure to insert your parameter values into it. That's your missing piece.



          Here's an example stored procedure:



          CREATE PROC [ASTONE].[LogEvent] 
          (
          @message nvarchar(max),
          @level int,
          @logger nvarchar(1024)
          )
          AS
          INSERT INTO [ASTONE].[EventLogs]
          ( message, level, logger )
          VALUES( @message, @level, @logger)


          I am guessing about the layout of your EventLogs table and the types and definitions of the parameters.



          And then your commandText attribute would look like this:



           commandText="[ASTONE].[LogEvent]"





          share|improve this answer


























          • Hi! Thank you so much for replying. Unfortunately when I try your method I get this error: Exception: System.Data.SqlClient.SqlException (0x80131904): The request for procedure 'EventLogs' failed because 'EventLogs' is a table object.

            – JianYA
            Dec 29 '18 at 0:13











          • AH! Then that is your core problem. (I wondered whether EventLogs was a stored proc: it sounded like a table name!)

            – Ann L.
            Dec 29 '18 at 0:19











          • NLog uses a SqlCommand object. That represents a call to a stored procedure, or (sometimes) a SQL insert or update statement.

            – Ann L.
            Dec 29 '18 at 0:20











          • You will need to write a stored procedure that takes your parameters and inserts records into EventLogs, and put that procedure's name in the commandText tag.

            – Ann L.
            Dec 29 '18 at 0:20













          • Hi! Thanks for helping. I have another question. Do I just put that as a comment? I'm unsure of where to put the command

            – JianYA
            Dec 29 '18 at 0:41
















          3














          This is from memory, but I think your commandText value would need to be this:



          commandText="[ASTONE].[EventLogs]"


          The separating . needs to be outside the square brackets.



          Since you specify the database name in the connection string, you shouldn't need it as part of the command text.



          UPDATED WITH NEW INFORMATION



          Since ASTONE.EventLogs is a table, you will need to write a stored procedure to insert your parameter values into it. That's your missing piece.



          Here's an example stored procedure:



          CREATE PROC [ASTONE].[LogEvent] 
          (
          @message nvarchar(max),
          @level int,
          @logger nvarchar(1024)
          )
          AS
          INSERT INTO [ASTONE].[EventLogs]
          ( message, level, logger )
          VALUES( @message, @level, @logger)


          I am guessing about the layout of your EventLogs table and the types and definitions of the parameters.



          And then your commandText attribute would look like this:



           commandText="[ASTONE].[LogEvent]"





          share|improve this answer


























          • Hi! Thank you so much for replying. Unfortunately when I try your method I get this error: Exception: System.Data.SqlClient.SqlException (0x80131904): The request for procedure 'EventLogs' failed because 'EventLogs' is a table object.

            – JianYA
            Dec 29 '18 at 0:13











          • AH! Then that is your core problem. (I wondered whether EventLogs was a stored proc: it sounded like a table name!)

            – Ann L.
            Dec 29 '18 at 0:19











          • NLog uses a SqlCommand object. That represents a call to a stored procedure, or (sometimes) a SQL insert or update statement.

            – Ann L.
            Dec 29 '18 at 0:20











          • You will need to write a stored procedure that takes your parameters and inserts records into EventLogs, and put that procedure's name in the commandText tag.

            – Ann L.
            Dec 29 '18 at 0:20













          • Hi! Thanks for helping. I have another question. Do I just put that as a comment? I'm unsure of where to put the command

            – JianYA
            Dec 29 '18 at 0:41














          3












          3








          3







          This is from memory, but I think your commandText value would need to be this:



          commandText="[ASTONE].[EventLogs]"


          The separating . needs to be outside the square brackets.



          Since you specify the database name in the connection string, you shouldn't need it as part of the command text.



          UPDATED WITH NEW INFORMATION



          Since ASTONE.EventLogs is a table, you will need to write a stored procedure to insert your parameter values into it. That's your missing piece.



          Here's an example stored procedure:



          CREATE PROC [ASTONE].[LogEvent] 
          (
          @message nvarchar(max),
          @level int,
          @logger nvarchar(1024)
          )
          AS
          INSERT INTO [ASTONE].[EventLogs]
          ( message, level, logger )
          VALUES( @message, @level, @logger)


          I am guessing about the layout of your EventLogs table and the types and definitions of the parameters.



          And then your commandText attribute would look like this:



           commandText="[ASTONE].[LogEvent]"





          share|improve this answer















          This is from memory, but I think your commandText value would need to be this:



          commandText="[ASTONE].[EventLogs]"


          The separating . needs to be outside the square brackets.



          Since you specify the database name in the connection string, you shouldn't need it as part of the command text.



          UPDATED WITH NEW INFORMATION



          Since ASTONE.EventLogs is a table, you will need to write a stored procedure to insert your parameter values into it. That's your missing piece.



          Here's an example stored procedure:



          CREATE PROC [ASTONE].[LogEvent] 
          (
          @message nvarchar(max),
          @level int,
          @logger nvarchar(1024)
          )
          AS
          INSERT INTO [ASTONE].[EventLogs]
          ( message, level, logger )
          VALUES( @message, @level, @logger)


          I am guessing about the layout of your EventLogs table and the types and definitions of the parameters.



          And then your commandText attribute would look like this:



           commandText="[ASTONE].[LogEvent]"






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Dec 29 '18 at 0:27

























          answered Dec 28 '18 at 23:47









          Ann L.Ann L.

          11.4k42654




          11.4k42654













          • Hi! Thank you so much for replying. Unfortunately when I try your method I get this error: Exception: System.Data.SqlClient.SqlException (0x80131904): The request for procedure 'EventLogs' failed because 'EventLogs' is a table object.

            – JianYA
            Dec 29 '18 at 0:13











          • AH! Then that is your core problem. (I wondered whether EventLogs was a stored proc: it sounded like a table name!)

            – Ann L.
            Dec 29 '18 at 0:19











          • NLog uses a SqlCommand object. That represents a call to a stored procedure, or (sometimes) a SQL insert or update statement.

            – Ann L.
            Dec 29 '18 at 0:20











          • You will need to write a stored procedure that takes your parameters and inserts records into EventLogs, and put that procedure's name in the commandText tag.

            – Ann L.
            Dec 29 '18 at 0:20













          • Hi! Thanks for helping. I have another question. Do I just put that as a comment? I'm unsure of where to put the command

            – JianYA
            Dec 29 '18 at 0:41



















          • Hi! Thank you so much for replying. Unfortunately when I try your method I get this error: Exception: System.Data.SqlClient.SqlException (0x80131904): The request for procedure 'EventLogs' failed because 'EventLogs' is a table object.

            – JianYA
            Dec 29 '18 at 0:13











          • AH! Then that is your core problem. (I wondered whether EventLogs was a stored proc: it sounded like a table name!)

            – Ann L.
            Dec 29 '18 at 0:19











          • NLog uses a SqlCommand object. That represents a call to a stored procedure, or (sometimes) a SQL insert or update statement.

            – Ann L.
            Dec 29 '18 at 0:20











          • You will need to write a stored procedure that takes your parameters and inserts records into EventLogs, and put that procedure's name in the commandText tag.

            – Ann L.
            Dec 29 '18 at 0:20













          • Hi! Thanks for helping. I have another question. Do I just put that as a comment? I'm unsure of where to put the command

            – JianYA
            Dec 29 '18 at 0:41

















          Hi! Thank you so much for replying. Unfortunately when I try your method I get this error: Exception: System.Data.SqlClient.SqlException (0x80131904): The request for procedure 'EventLogs' failed because 'EventLogs' is a table object.

          – JianYA
          Dec 29 '18 at 0:13





          Hi! Thank you so much for replying. Unfortunately when I try your method I get this error: Exception: System.Data.SqlClient.SqlException (0x80131904): The request for procedure 'EventLogs' failed because 'EventLogs' is a table object.

          – JianYA
          Dec 29 '18 at 0:13













          AH! Then that is your core problem. (I wondered whether EventLogs was a stored proc: it sounded like a table name!)

          – Ann L.
          Dec 29 '18 at 0:19





          AH! Then that is your core problem. (I wondered whether EventLogs was a stored proc: it sounded like a table name!)

          – Ann L.
          Dec 29 '18 at 0:19













          NLog uses a SqlCommand object. That represents a call to a stored procedure, or (sometimes) a SQL insert or update statement.

          – Ann L.
          Dec 29 '18 at 0:20





          NLog uses a SqlCommand object. That represents a call to a stored procedure, or (sometimes) a SQL insert or update statement.

          – Ann L.
          Dec 29 '18 at 0:20













          You will need to write a stored procedure that takes your parameters and inserts records into EventLogs, and put that procedure's name in the commandText tag.

          – Ann L.
          Dec 29 '18 at 0:20







          You will need to write a stored procedure that takes your parameters and inserts records into EventLogs, and put that procedure's name in the commandText tag.

          – Ann L.
          Dec 29 '18 at 0:20















          Hi! Thanks for helping. I have another question. Do I just put that as a comment? I'm unsure of where to put the command

          – JianYA
          Dec 29 '18 at 0:41





          Hi! Thanks for helping. I have another question. Do I just put that as a comment? I'm unsure of where to put the command

          – JianYA
          Dec 29 '18 at 0:41


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53965379%2fnlog-adding-a-database-schema-name%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Monofisismo

          Angular Downloading a file using contenturl with Basic Authentication

          Olmecas