How to hide or mask paths from "Microsoft.Hosting.Lifetime" traces using serilog in the appsetting for an API project.

aivalo

New member
Joined
Apr 1, 2022
Messages
2
Programming Experience
5-10
How to hide or mask paths from "Microsoft.Hosting.Lifetime" traces using serilog in the appsetting for an API project.

Having this configuration:
JavaScript:
"Serilog": {
    "MinimumLevel": {
      "Default": "Information",
      "Override": {
        "Microsoft.Hosting.Lifetime": "Information"
       }
      },
      "Enrich": [ "FromLogContext", "WithMachineName", "WithProcessId", "WithThreadId", "WithSensitiveDataMasking" ],
      "WriteTo": [
        { "Name": "Console" },
        {
          "Name": "File",
          "Args": {
            "path": "*****",
            "fileSizeLimitBytes": 1000000,
            "rollOnFileSizeLimit": true,
            "shared": true,
            "outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} {Level} {MachineName} {ProcessId} {Message}{NewLine:l}{Exception:l}"
          }
        }
      ]
    }

I want to hide the information about the content path, etc in the log:
C#:
[16:46:13 INF] Application Starting
[16:46:13 INF] User profile is available. Using 'C:\Users\user\AppData\Local\ASP.NET\DataProtection-Keys' as key repository and Windows DPAPI to encrypt keys at rest.
[16:46:14 INF] Now listening on: https://localhost:44301
[16:46:14 INF] Application started. Press Ctrl+C to shut down.
[16:46:14 INF] Hosting environment: Local
[16:46:14 INF] Content root path: C:\Users\user\Documents\SPM\Projects\SPM-api_branch_Initial_work\src\SPMAPI

Let me know if you know how to do it.
 
Last edited by a moderator:
Sounds more like a SeriLog question rather than a C# programming question.
 
In your shoes, my first stab at this without RFTM-ing is to just try changing "Information" on line 5 to either "Fatal" or "None", just to see what happens. Regardless whether it successfully gets the effect I want or not, I would next then start reading the documentation.
 
Show us your code where you created your custom filter, and how you registered it.
 
Back
Top Bottom