mohsen dorparasti
mohsen dorparasti

Reputation: 8415

where to instantiate logging class to log all logs of a request once?

there is a logging class that logs user activities into a database .

as I didn't wanted to write logging codes in all methods ( violating SRP principle if I'm not wrong ) , I decided to define events and raise them in methods .

then add a class that contains event handling methods to subscribe to events and use logging class to log necessary data into database.

another point is that during a request several events may raise and I want to catch them all and add logs to the database in one transaction .

now I wonder where and how should I instantiate this handling class to achieve this goal ?

I'm using Asp.net WebForms .

Upvotes: 1

Views: 167

Answers (1)

muratgu
muratgu

Reputation: 7311

SRP would not be violated by adding logging statements into your methods.

You shouldn't re-invent the wheel unless you have a very specific need. Use Log4Net or some other logging framework.

Upvotes: 2

Related Questions