E
E
Eugene2013-11-28 09:32:26
.NET
Eugene, 2013-11-28 09:32:26

How to organize logging of user actions in the program?

Hello.
I am developing one software package and the question arose about logging (log) of user actions.
For example, an authorized user changed the customer's last name (textbox) and added it to a new category (combobox) and wrote a note (richtextbox).
Question: what is the best way to implement the recording of all actions (changes in controls) to a log file (it doesn't matter, in txt or in mysql)?

Answer the question

In order to leave comments, you need to log in

6 answer(s)
V
veitmen, 2013-11-29
@gloomkolomna

Greetings.
I read the answers. There are several comments.
1. Log4Net is great. You have already been written about him, take him. Install via NuGet.
2. Don't think about doing logging in the database itself, No triggers, etc. In general, forget that you can do anything in the database other than storing data. There is only one reason to do something in the database - this is a strict customer requirement that cannot be changed.
3. I don't think that you need to record the changes in controls. Rather, you need to record not just changes to controls, but changes made to the data store. Because while I am editing the post, it does not need to be logged, it is necessary to log that I saved the changes.
4. You have a business logic layer, and log information about what is happening in the system there.
5. There is another good thing called aspect-oriented programming. See what it is and how it can help in creating a logging system.

A
Alexander, 2013-11-28
@Papagatto

There is a handy NLog library. Pretty easy to use. You can set up logging to the database and to a text file, and just do anywhere.
http://nlog-project.org/

D
Denis Kozlov, 2014-01-08
@deniskozlov

NLog( nlog-project.org ) is good, I have been using it for a long time from the server to the vinphone, I pop it, as they say, everywhere)) There is an article comparing logging frameworks habrahabr.ru/post/98638

X
xflash, 2013-11-28
@xflash

It is necessary to log change of controls or already change of record in the table after saving?
- if the records are in tables, it is easier to implement in the database through triggers. By comparing the value before and after saving.
- if it is controls, then they are probably values ​​from the database through the data source. So you can work with changes in them!
- if the very fact of changes is important, and not the saved value - add the handling of the change event to each control and write in txt on this event.

A
afiskon, 2013-11-30
@afiskon

If from time to time you just need to figure out who did what, write to a file. If a business wants to look at the logs itself with filtering by date and so on, write to the DBMS.

E
Eugene, 2014-01-28
@gloomkolomna

And tell me such a thing, here I write the following in the config:

<target name="mysql" xsi:type="Database"
            keepConnection="true"
            useTransactions="false"
            dbProvider="MySql.Data.MySqlClient"
            connectionString="Server=****;Database=****;Uid=****;Password=****;Connect Timeout=5;"
            commandText="INSERT INTO tbl_log (log_message) VALUES (@log_message)">
      <parameter name="@log_message" layout="${message}"/>
    </target>

But it doesn't work (doesn't add records). What could be the error (well, obviously, in connecting to mysql, but how then to do it right?)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question