Application Registration Architecture

I am writing an ASP.NET MVC3 application and, as expected, the application will be safe, I need a good enterprise application architecture.

So, I searched for existing loggin frameworks and selected NLog . Therefore, at this moment I was stuck in creating a database schema for magazines.

Does anyone have any good experience in this area? It involves registering a set of actions, such as interacting with system objects, background work, user actions, transaction transactions, etc.

+4
source share
2 answers

I have been using NLog for a while and I am very pleased with this. What I like most about NLog is that you can configure different log levels to write to different files and / or databases. This is a very powerful logging library.

To enter the database, you can use something like below in your configuration. This is similar to what I use in the company I work for.

<target xsi:type="Database" name="TestDatabaseLogging" connectionString="Data Source=127.0.0.1;Initial Catalog=NLog_Test;User ID=MyLogin;Password=MyPassword" dbDatabase="NLog_Test"> <commandText> insert into INNO_LOG ([createDate], [Origin], [LogLevel], [Message], [Exception], [StackTrace]) values (@createDate, @origin, @logLevel, @message, @exception, @stackTrace) </commandText> <parameter name="@createDate" layout="${date}"/> <parameter name="@origin" layout="${callsite}"/> <parameter name="@logLevel" layout="${level}"/> <parameter name="@message" layout="${message}"/> <parameter name="@exception" layout="${exception:format=Message,StackTrace}"/> <parameter name="@stackTrace" layout="${stacktrace}"/> </target> 

You can use the rules section to register different levels for different files, see the example below;

  <rules> <logger name="*" minlevel="Fatal" writeTo="mail" /> <logger name="*" minlevel="Error" writeTo="TestDatabaseLogging" /> <logger name="*" minlevel="Debug" writeTo="file-debug" /> <logger name="*" minlevel="Info" writeTo="file" /> <!--Log to specific files for specific classes.--> <logger name="_Default" minlevel="Trace" writeTo="file-default" /> <logger name="TestClass" minlevel="Trace" writeTo="file-testclass" /> </rules> 

EDIT: added a possible table layout for recording information.

 Id | int CreateDate | datetime LogLevel | nvarchar Message | nvarchar(max) Exception | nvarchar(max) StackTrace | nvarchar(max) SourceUrl | nvarchar(255) UserId | uniqueidentifier OrderId | int 

The above layout is just a rough idea. It completely depends on what you want to enter this table. Although you should try, if by default you can add additional parameters other than those used by NLog.

+9
source

As Rob replied. Stick with NLog :)

If you need a good viewer, be sure to use Sentinal as a free nLog viewer :)

Do not forget that you can programmatically include sections of the journal, and during the production process - view certain areas of the website. And then look at them in real time using Sentinal.

enter image description here


another option is to take advantage of LoggR.net . These data streams (i.e. Errors or registration data in this case) in real time. I think this is using awesome SignalR to use WebSockets or Long Polling (2 in real time) :)

enter image description here

+7
source

Source: https://habr.com/ru/post/1385295/


All Articles