Here is a lighthearted attempt at generalizing the discussion of Hurwitz' formula in Hartshorne to higher dimensions.

Let $f:Y\to X$ be morphism of schemes over a field $k$. Assume that $X$ and $Y$ are integral and smooth of dimension $n$, and that $f$ is finite, dominant and separable.

Consider the exact sequence
\begin{equation*}
f^* \Omega_X \to \Omega_Y \to \Omega_{Y/X} \to 0.
\end{equation*}
Separability of the extension of fields $k(X)\subseteq k(Y)$ is equivalent to the vanishing $\Omega_{k(Y)/k(X)}=0$. Thus the map $f^*\Omega_X\to \Omega_Y$ is surjective at the generic point of $Y$. It follows that it is also injective there, since the two sheaves involved are locally free of the same rank. We conclude that $f^*\Omega_X\to \Omega_Y$ is injective everywhere, since $Y$ is integral.

Exterior powers of injective maps of modules that are finite and free over a ring are again injective. Thus the natural map $f^*\omega_X\to \omega_Y$ is injective. Tensoring with $\omega_Y^{-1}$, we obtain an invertible ideal sheaf $f^*\omega_Y\otimes \omega_Y^{-1} \subseteq \mathscr O_Y$. The corresponding effective Cartier divisor $R$ is called the *ramification divisor* of the cover $f:Y\to X$. By construction there is a natural isomorphism $f^*\omega_X(R)\xrightarrow\sim \omega_Y$.

Let $P\in Y$ be a point of codimension 1. We next show that
\begin{equation*}
\operatorname{length}_{\mathscr O_{Y,P}}\mathscr O_{R,P} = \operatorname{length}_{\mathscr O_{Y,P}} (\Omega_{Y/X})_P.
\end{equation*}
(I apologise in advance for the inelegant proof.)
This will imply the Weil divisor associated with $R$ is
\begin{equation*}
\sum_{F\subseteq Y} (\operatorname{length}_{\mathscr O_{Y,F}} \Omega_{Y/X}) \cdot F,
\end{equation*}
where the sum runs over all prime divisors of $Y$. In particular, the complement of $R$ in $Y$ is the largest open subset restricted to which $f$ is unramified.

Denote $A:=\mathscr O_{Y,P}$ and let $t\in A$ be a uniformizer. Choose bases around $P$ for the rank-$n$ locally free sheaves $f^*\Omega_Y$ and $\Omega_Y$. The map $(f^*\Omega_Y)_P\to (\Omega_X)_P$ is then given by a matrix $\alpha$, which we may assume to be in Smith normal form:
\begin{equation*}
\alpha =
\begin{bmatrix}
t^{a_1} & & \\
& \ddots & \\
& & t^{a_n}
\end{bmatrix},
\end{equation*}
where the $a_i\ge 0$ are integers. Here there are no zeroes along the diagonal because $\alpha$ tensored with $\operatorname{Frac}(A)$ must be surjective. It easy to see that
\begin{equation*}
\mathscr O_{R,P} \cong A/(\det \alpha) = A/(t^{\sum a_i}),
\end{equation*}
while
\begin{equation*}
(\Omega_{Y/X})_P\cong \oplus_{i\ge 0}^n A/(t^{a_i}),
\end{equation*}
so these two modules have the same length $\sum a_i$.

Let $r(P)$ be the *ramification* of $f$ at $P$: this is the valuation of the image of any uniformizer of $\mathscr O_{X,f(P)}$ in $\mathscr O_{Y,P}$. Assume that the characteristic of $k$ does not divide $r(P)$, that the finite field extension $k(f(P))\subseteq k(P)$ is separable, and that the finitely generated one $k\subseteq k(f(P))$ is separably generated. We show that under these circumstances
\begin{equation*}
\operatorname{length}_{\mathscr O_{Y,P}} (\Omega_{Y/X})_P = r(P)-1.
\end{equation*}

Denote
\begin{align*}
r &:= r(P), \\
A &:= \mathscr O_{X,f(P)}, \\
B &:= \mathscr O_{Y,P}.
\end{align*}
Thus we have inclusions $k\subseteq B\subseteq A$. Denote the maximal ideal of $A$ by ${\frak m}_A$, its residue field by $k_A$, and similarly for $B$. Thus ${\frak m}_A = (t_A)$ and ${\frak m}_B = (t_B)$ with $t_B = u t_A^r$, where $u\in A^\times$ is a unit.

By hypothesis there is a transcendence basis $\bar f_1,\dotsc, \bar f_{n-1}$ of $k_B$ over $k$ such that the extension $k_B/k(\bar f_1,\dotsc,\bar f_{n-1})$ is separable (hence has no relative differentials). Choose lifts $f_1,\dotsc, f_{n-1}\in B$ of the elements of this transcendence basis. Looking at the exact sequence
\begin{equation*}
{\frak m}_B/{\frak m}_B^2 \xrightarrow{d} \Omega_B \otimes k_B \to \Omega_{k_B} \to 0
\end{equation*}
and applying Nakayama we see that the map $B^{\oplus n} \to \Omega_B$ that sends
\begin{equation*}
e_i \mapsto
\begin{cases}
df_i & \text{if }i\le n-1\\
dt_B & \text{if }i = n
\end{cases}
\end{equation*}
is surjective. Let $K$ denote its kernel. Then $\operatorname{Tor}_1^B(\Omega_B,k_B)$ surjects onto $K\otimes_B k_B$. From the fact that $\Omega_B$ is free, it follows that $K=0$. Thus the free $B$-module $\Omega_B$ has $df_1,\dotsc, df_{n-1}, dt_B$ as a basis.

From the fact that $k_A/k_B$ is separable, it follows that $k_A/k(\bar f_1,\dotsc, \bar f_{n-1})$ is as well, so by the preceding argument the free $A$-module $\Omega_A$ has $df_1,\dotsc, df_{n-1}, dt_A$ as a basis.

The relative differentials $\Omega_{A/B}$ are thus the quotient of $\Omega_A$ by the submodule generated by $df_1,\dotsc, df_{n-1}, dt_B$. Denote by $M$ the itermediate quotient of $\Omega_A$ by $df_1,\dotsc, df_{n-1}$. Then $M$ is freely generated by the image of $dt_A$. Write
\begin{equation*}
dt_B = t_A^r du + u r t_A^{r-1} dt_A
\end{equation*}
in $\Omega_A$. In $M$ we have $du = f dt_A$ for some $f\in A$, so $dt_B = u' t_A^{r-1}dt_A$, for some $u'\in A$. From the fact that $r\ne 0$ in $k$, it follows that $u'$ is a unit. Hence the map
\begin{equation*}
A/(t_A^{r-1}) \xrightarrow{\cdot dt_A} \Omega_{A/B}
\end{equation*}
is an isomorphism and $\operatorname{length}_A \Omega_{A/B} = r-1$ as claimed.

Question:"In Hartshorne IV.2, notions related to ramification and branching are introduced, but only for curves. The main result is the Hurwitz formula." $$\text{ }$$Answer:This answer was deleted by Stefan Kohl, still it may have interest for you. There is an etale version of the Hurwitz formula. If $f: X^n \rightarrow Y^n$ is a finite etale map of projective schemes of dimension $n$ over a field $k$, there is the following formula (an "etale Hurwitz formula"): $$Et.\text{ }p_a(X)=deg(f)p_a(Y)+(-1)^n(deg(f)-1).$$ $\endgroup$