Forum Discussion

yossi_br's avatar
yossi_br
Ideator I
7 months ago
Solved

Create log file with CCO.Logger

Hello,
I want to start using the CCO.Logger for creating log files and I didn't find any information about this. The only thing I found is a topic that the appsettings needs to be configured. I'm assuming that over there I can manage the writing level and also where the log file will be created. Currently my appsettings is looking like this:

{
	"LoggerConfiguration": {
		"MinimumLevel": "Fatal",
		"WriteTo": [
			{ "Name": "Console" },
			{ "Name": "File" },
			{ "Name": "EventLog" }
		]
	}
}

Is someone can point me to relevant documentation, or give me some examples, I will appreciate it.

Thanks in advance

6 Replies

  • in Release14+ in server side method by default CCO object should always be available.

    so it should be enough:

    If it is necessary to add new information to logs from Server method, then it is possible to use CCO.Logger and CCO.LoggerFactory.
    In simple case we can user CCO.Logger.LogError('message') as you can see in the following picture:

     

    • yossi_br's avatar
      yossi_br
      Ideator I

      Hi, thanks for the reply, but sorry, I didn't understand.
      I added this line in my server method, run it, and then what?
      Where should the log be written?
      I'm pretty sure that the appsettings file in the server needs to be configured.



      • vkutsen's avatar
        vkutsen
        Ideator III

        and this information will be written into general aras logs (as you mentioned, controlled by appsetting.json file), and depending on the minimum level configured, information will be written into logs.

  • If it helps and you want an alternative what I have done is create a β€œdebug log” item type and a variable (either generic or method/application specific) and call a function within the methods to add data to the debug log item during execution. Having the variable allows disabling it without modifying the method each time. 

     

  • Hi,
    In the end, I used my own creative approach, I created a DLL with a reference to Aras.Server.Core.dll and built a class that creates a logger using Serilog. It reads the MinimumLevel from appsettings.json and writes logs accordingly to a predefined path.

    You can also use CCO.Logger, but its logs are written to Server\logs, so I built this DLL to generate a custom log file for any project I want. It also knows when to write logs based on the MinimumLevel defined in appsettings.json.