Automate

 View Only
  • 1.  Evolve Tip - enabling writing of Evolve Logs to database

    Posted 23 days ago
    Edited by Sigrid Kok 22 days ago

    This time it is not Sigrid, but a user :)

    By default, Evolve writes logs to text files, that is very painful to analyze and search. Fortunately they use NLog and it can be easily configured to write logs directly to database in addition to text files.

    Edit the file svr\NLog.config as following replacing <SERVER_NAME> and <DATABASE_NAME> with your actual values:

    <?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" throwExceptions="false" internalLogLevel="Warn" internalLogFile="${basedir}\Logs\nlog-app.log" autoReload="true">

      <!--

      See http://nlog-project.org/wiki/Configuration_file

      for information on customizing logging rules and outputs.

       -->

      <extensions>

        <!--enable NLog.Web for ASP.NET Core-->

      </extensions>

      <targets>

        <!-- file targets -->

        <target name="asyncFile" xsi:type="AsyncWrapper" queueLimit="10000" timeToSleepBetweenBatches="50" batchSize="100" overflowAction="Block">

          <target xsi:type="File" name="f" fileName="${basedir}\Logs\Evolve_logs_${date:format=yyyy-MM-dd}.log" maxArchiveFiles="10" archiveAboveSize="10485760" archiveNumbering="DateAndSequence" encoding="Unicode" layout="${longdate}|${uppercase:${level}}|${threadid}|${machinename}|${callsite}|${message}|${exception:format=tostring}" />

        </target>

        <!-- database targets -->

        <target name="database" xsi:type="Database" dbProvider="System.Data.SqlClient" connectionString="Data Source=<SERVER_NAME>;Initial Catalog=<DATABASE_NAME>;Trusted_Connection=True;" commandText="INSERT INTO EvolveLog(EventDateTime, EventLevel, ThreadId, MachineName, CallSite, Message, Exception) VALUES (@EventDateTime, @EventLevel, @ThreadId, @MachineName, @CallSite, @Message, @Exception)">

          <!-- parameters for the command -->

          <parameter name="@EventDateTime" layout="${longdate}" />

          <parameter name="@EventLevel" layout="${uppercase:${level}}" />

          <parameter name="@ThreadId" layout="${threadid}" />

          <parameter name="@MachineName" layout="${machinename}" />

          <parameter name="@CallSite" layout="${callsite}" />

          <parameter name="@Message" layout="${message}" />

          <parameter name="@Exception" layout="${exception:format=tostring}" />

        </target>

      </targets>

      <rules>

        <!-- add your logging rules here -->

        <logger name="*" minlevel="Error" writeTo="asyncFile" enabled="true" />

        <logger name="*" minlevel="Warn" writeTo="database" enabled="true" />

      </rules>

    </nlog>

    Then you can create a table in database using this code:

    CREATE TABLE [dbo].[EvolveLog](
    [id] [uniqueidentifier] ROWGUIDCOL  NOT NULL,
    [EventDateTime] [datetime2](4) NOT NULL,
    [EventLevel] [nvarchar](10) NULL,
    [ThreadId] [int] NULL,
    [MachineName] [nvarchar](20) NULL,
    [CallSite] [nvarchar](500) NULL,
    [Message] [nvarchar](max) NULL,
    [Exception] [nvarchar](max) NULL,
     CONSTRAINT [PK_EvolveLog] PRIMARY KEY CLUSTERED 
    (
    [id] ASC
    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
    ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
    GO
    ALTER TABLE [dbo].[EvolveLog] ADD  CONSTRAINT [DF_EvolveLog_id]  DEFAULT (newid()) FOR [id]
    GO

    Then give the account you are running Evolve in IIS with INSERT authorizations for this table and you are good to go! Put it in your favorite reporting tool to analyze logs or give someone access. Enjoy!


    P.S.: You can change level of logs to Error, Warn, Info or Debug here as required:
        <logger name="*" minlevel="Warn" writeTo="database" enabled="true" />

    P.P.S.: Settings in Evolve will only change level for files logging ; if you need to change log level for database, you need to edit NLog.config - changes are applied immediately.



    ------------------------------
    Alexey Skotnikov
    GPO, Data Governance
    ABBOTT RAPID DX INTERNATIONAL LIMITED
    ------------------------------



  • 2.  RE: Evolve Tip - enabling writing of Evolve Logs to database

    Employee
    Posted 23 days ago

    Nice tip, Alexey!  Does this run ongoing via some type of trigger or do you run on-demand?

    Thanks,

    Sigrid



    ------------------------------
    Sigrid Kok
    *Precisely Software Inc.
    ------------------------------



  • 3.  RE: Evolve Tip - enabling writing of Evolve Logs to database

    Posted 23 days ago

    It is online - writing to database at the same moment as it writes to normal text log files. So you get latest and greatest info always.



    ------------------------------
    Alexey Skotnikov
    GPO, Data Governance
    ABBOTT RAPID DX INTERNATIONAL LIMITED
    ------------------------------



  • 4.  RE: Evolve Tip - enabling writing of Evolve Logs to database

    Employee
    Posted 20 days ago

    this is fantastic, thanks for taking the time to share! We appreciate you @Alexey Skotnikov 

    CC: @Hammad Naeem @Charles Howard @Martin Monka @Harsimran Dhami 



    ------------------------------
    Jayasri Varyani
    SE
    Precisely Software Inc.
    ------------------------------