Answer the question
In order to leave comments, you need to log in
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
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.
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/
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
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.
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.
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>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question