Added logging, added Elmah error logging

This commit is contained in:
2025-09-27 13:51:30 +02:00
parent cea3e571f1
commit fad7f8454f
5 changed files with 51 additions and 35 deletions

View File

@@ -12,11 +12,13 @@ public class LdapService : IDisposable
{
private readonly LdapOptions _opts;
private readonly LdapConnection _conn;
private ILogger _logger;
public LdapService(IOptions<LdapOptions> options)
public LdapService(IOptions<LdapOptions> options, ILogger<LdapService> logger)
{
_opts = options.Value;
_conn = new LdapConnection { SecureSocketLayer = _opts.UseSsl };
_logger = logger;
ConnectAndBind();
}
@@ -26,7 +28,15 @@ public class LdapService : IDisposable
{
Console.WriteLine(_opts.Host);
Console.WriteLine(_opts.Port);
_conn.Connect(_opts.Host, _opts.Port);
try
{
_conn.Connect(_opts.Host, _opts.Port);
}
catch (SystemException ex)
{
_logger.LogCritical("Unable to connect to LDAP: {ex.Message}\n{ex.StackTrace}", [ex.Message, ex.StackTrace]);
throw;
}
}
_conn.Bind(_opts.BindDn, _opts.BindPassword);
}